Advertisement
Guest User

Untitled

a guest
Dec 5th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. static int lua_regsound_old(lua_State *L)
  2. {
  3.     int argc = lua_gettop(L);
  4.     #ifndef SKIP_ERROR_HANDLING
  5.         if (argc != 2) return luaL_error(L, "wrong number of arguments");
  6.     #endif
  7.     u32 time = luaL_checkinteger(L, 1);
  8.     u32 samplerate = luaL_checkinteger(L, 2);
  9.     u32 mem_base;
  10.     MICU_SampleRate smplrt;
  11.     if (samplerate <= 8200){
  12.         smplrt = MICU_SAMPLE_RATE_8180;
  13.         samplerate = 8180;
  14.         mem_base = 0x4000;
  15.     }else if (samplerate <= 12000){
  16.         smplrt = MICU_SAMPLE_RATE_10910;
  17.         samplerate = 10910;
  18.         mem_base = 0x6000;
  19.     }else if (samplerate <= 18000){
  20.         smplrt = MICU_SAMPLE_RATE_16360;
  21.         samplerate = 16360;
  22.         mem_base = 0x8000;
  23.     }else{
  24.         smplrt = MICU_SAMPLE_RATE_32730;
  25.         samplerate = 32730;
  26.         mem_base = 0x10000;
  27.     }
  28.     u32 micbuf_pos = 0;
  29.     u32* micbuf = (u32*)memalign(0x1000, mem_base * time);
  30.     micInit((u8*)micbuf, mem_base * time);
  31.     u32 micbuf_datasize = micGetSampleDataSize();
  32.     u32 audiobuf_size = time * samplerate * 2;
  33.     //u8* audiobuf = (u8*)linearAlloc(audiobuf_size);
  34.     //u32 audiobuf_pos = 0;
  35.     MICU_StartSampling(MICU_ENCODING_PCM16_SIGNED, smplrt, 0, micbuf_datasize, false);
  36.     bool isSampling;
  37.     MICU_IsSampling(&isSampling);
  38.     while (isSampling) MICU_IsSampling(&isSampling);
  39.     //memcpy(audiobuf, micbuf, audiobuf_size);
  40.     micExit();
  41.     free(micbuf);  
  42.     wav* songFile = (wav*)malloc(sizeof(wav));
  43.     songFile->audiobuf = (u8*)micbuf;
  44.     songFile->audiobuf2 = NULL;
  45.     songFile->big_endian = false;
  46.     songFile->mem_size = 0;
  47.     songFile->ch = 0xDEADBEEF;
  48.     songFile->size = audiobuf_size;
  49.     songFile->samplerate = samplerate;
  50.     strcpy(songFile->author,"");
  51.     strcpy(songFile->title,"");
  52.     songFile->isPlaying = false;
  53.     songFile->bytepersample = 2;
  54.     songFile->magic = 0x4C534E44;
  55.     lua_pushinteger(L,(u32)songFile);
  56.     return 1;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement