Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int lua_regsound_old(lua_State *L)
- {
- int argc = lua_gettop(L);
- #ifndef SKIP_ERROR_HANDLING
- if (argc != 2) return luaL_error(L, "wrong number of arguments");
- #endif
- u32 time = luaL_checkinteger(L, 1);
- u32 samplerate = luaL_checkinteger(L, 2);
- u32 mem_base;
- MICU_SampleRate smplrt;
- if (samplerate <= 8200){
- smplrt = MICU_SAMPLE_RATE_8180;
- samplerate = 8180;
- mem_base = 0x4000;
- }else if (samplerate <= 12000){
- smplrt = MICU_SAMPLE_RATE_10910;
- samplerate = 10910;
- mem_base = 0x6000;
- }else if (samplerate <= 18000){
- smplrt = MICU_SAMPLE_RATE_16360;
- samplerate = 16360;
- mem_base = 0x8000;
- }else{
- smplrt = MICU_SAMPLE_RATE_32730;
- samplerate = 32730;
- mem_base = 0x10000;
- }
- u32 micbuf_pos = 0;
- u32* micbuf = (u32*)memalign(0x1000, mem_base * time);
- micInit((u8*)micbuf, mem_base * time);
- u32 micbuf_datasize = micGetSampleDataSize();
- u32 audiobuf_size = time * samplerate * 2;
- //u8* audiobuf = (u8*)linearAlloc(audiobuf_size);
- //u32 audiobuf_pos = 0;
- MICU_StartSampling(MICU_ENCODING_PCM16_SIGNED, smplrt, 0, micbuf_datasize, false);
- bool isSampling;
- MICU_IsSampling(&isSampling);
- while (isSampling) MICU_IsSampling(&isSampling);
- //memcpy(audiobuf, micbuf, audiobuf_size);
- micExit();
- free(micbuf);
- wav* songFile = (wav*)malloc(sizeof(wav));
- songFile->audiobuf = (u8*)micbuf;
- songFile->audiobuf2 = NULL;
- songFile->big_endian = false;
- songFile->mem_size = 0;
- songFile->ch = 0xDEADBEEF;
- songFile->size = audiobuf_size;
- songFile->samplerate = samplerate;
- strcpy(songFile->author,"");
- strcpy(songFile->title,"");
- songFile->isPlaying = false;
- songFile->bytepersample = 2;
- songFile->magic = 0x4C534E44;
- lua_pushinteger(L,(u32)songFile);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement