Example #1
0
int main(int argc, char *argv[])
{
	CoInitializeEx(nullptr, COINIT_MULTITHREADED);

	char *buffer = new char[BUFFER_SIZE];

	if (buffer == nullptr)
		return -11;

	try
	{
		audio.open(XAUDIO2_DEBUG_ENGINE);
		DMSG("open");
		Wav wav("D:\\openAL\\11k16bitpcm.wav");
		uint32_t readSize = wav.read(buffer, BUFFER_SIZE);
		DVAR(readSize);
		wav.close();
		DMSG("play");
		audio.play(wav.getFormat(), buffer, wav.getSize());

		while (audio.isPlaying())
			Thread::sleep(10);
	}
	catch (...)
	{
		std::cout << "error" << std::endl;
	}

	DMSG("close");
	audio.close();

	CoUninitialize();

	return 0;
}
Example #2
0
JSValue *AudioProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{  
    if (!thisObj->inherits(&Audio::info)) {
        return throwError(exec, TypeError);
    }
    Audio *audio = static_cast<Audio*>(thisObj);
    switch (id) {
      case Audio::Play:
          audio->play();
          break;
      case Audio::Loop:
          audio->loop( args.size() > 0 ? args[0]->toInt32(exec) : -1 );
          break;
      case Audio::Stop:
          audio->stop();
          break;
      default:
          break;      
    }
    return jsUndefined();
}