欢迎光临散文网 会员登陆 & 注册

从CharGPT那边得到的另一种C++播放bytebeat的代码

2023-02-28 20:33 作者:苏联的球  | 我要投稿

// 声明必要的头文件 

#include <iostream>

#include <cstdlib> 

#include <cmath>

#include <algorithm> 

#include <fstream>

#include <string>

#include <Windows.h> 


using namespace std; 

// 定义缓冲区的大小

const int buffer_size = 2048; 

// 定义BYTEBEAT函数 

int bytebeat(int t) {    

// 这里可以定义一些BYTEBEAT的公式,然后返回一个处理后的声音   

 int sound = (t * 7 + t * (t >> 5) + t * (t >> 11)) & 0xff;    

return sound; }

int main() {    

// 创建一个缓冲区 

  short *buffer = new short[buffer_size];   

 // 将BYTEBEAT函数的结果放到缓冲区中

  for (int i = 0; i < buffer_size; i++)     {          

buffer[i] = bytebeat(i);    

}    

// 将缓冲区中的数据保存到文件    

ofstream out("bytebeat.dat", ios::binary);    

out.write((char*)buffer, buffer_size * sizeof(short));   

out.close();   

 // 将缓冲区中的数据播放出来   

 PlaySound("bytebeat.dat", NULL, SND_FILENAME | SND_ASYNC);    delete[] buffer;    return 0; }

从CharGPT那边得到的另一种C++播放bytebeat的代码的评论 (共 条)

分享到微博请遵守国家法律