// TODO: Add streaming support. bool SoundCtor(JSContext *ctx, unsigned argc, JS::Value *vp){ JS::CallArgs args = CallArgsFromVp(argc, vp); if(!Turbo::CheckForSingleArg(ctx, args, Turbo::String, __func__)) return false; struct Turbo::JSStringHolder<> file(ctx, JS_EncodeString(ctx, args[0].toString())); const std::string full_path = std::string(TS_GetContextEnvironment(ctx)->directories->sound) + file.string; if(!t5::IsFile(full_path)){ Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error no such file ") + file.string); return false; } SF_INFO info; SNDFILE *sound_file = sf_open(full_path.c_str(), SFM_READ, &info); //sf_command(sound_file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE); if(!sound_file){ Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error could not open file ") + file.string); return false; } int iters = 0; Sound *sound = nullptr; if(player.supportsFloat32()){ float buffer[0x8000]; sound = new Sound(player.load((float *)nullptr, 0, info.channels, info.samplerate, info.frames)); while(unsigned long this_read = sf_read_float(sound_file, buffer, 0x10000)){ player.addToSound(sound, buffer, SamplesToBytes(this_read)); iters++; } } else if(player.supportsInt16()){ short buffer[0x10000]; sound = new Sound(player.load((short *)nullptr, 0, info.channels, info.samplerate, info.frames)); while(unsigned long this_read = sf_read_short(sound_file, buffer, 0x10000)){ player.addToSound(sound, buffer, SamplesToBytes(this_read)); iters++; } } else{ puts(BRACKNAME " Error bad player on this platform"); } printf(BRACKNAME " SoundCtor Info loaded file %s in %i iterations\n", file.string, iters); sf_close(sound_file); args.rval().set(OBJECT_TO_JSVAL(sound_proto.wrap(ctx, sound))); return true; }
PlayerStatus_t PcmPlayer_Ksound_c::CommitMappedSamples() { PlayerStatus_t Status; int Result; unsigned char *FirstMappedSample = ( (unsigned char *) (SoundcardMappedBuffer->addr) + (SoundcardMappedBuffer->first / 8) + (SoundcardMappedOffset * (SoundcardMappedBuffer->step / 8)) ); st_relayfs_write(BufferType, PCMPLAYER_COMMIT_MAPPED_SAMPLES, FirstMappedSample, (unsigned int) SamplesToBytes((SoundcardMappedSamples * Q11_5_UNITY) / ResamplingFactor_x32), 0 ); Result = ksnd_pcm_mmap_commit(SoundcardHandle, SoundcardMappedOffset, SoundcardMappedSamples); if (Result < 0 || (snd_pcm_uframes_t) Result != SoundcardMappedSamples) { PCMPLAYER_ERROR("Underrun before commit (%d) for %s\n", -Result, Identity); Status = DeployUnderrunRecovery(); if (PlayerNoError != Status) return Status; } // no samples are now mapped SoundcardMappedSamples = 0; TimeOfNextCommit = 0; return PlayerNoError; }