Ejemplo n.º 1
0
int main(int argc, char* argv[]) {
  id = argc;

  Audio audio;

  char input;

  for (unsigned int i = 8192; i > 2; i /= 2) {
    audio.start(i);
    sleep(1);
    audio.stop();
  }
}
Ejemplo n.º 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();
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	CoInitializeEx(nullptr, COINIT_MULTITHREADED);

	try
	{
		audio.open(XAUDIO2_DEBUG_ENGINE);
		DMSG("open");
		Wav wav("D:\\openAL\\11k16bitpcm.wav");
		audio.stream(wav.getFormat());

		for (int i = 0; i < 2; ++i)
		{
			DMSG("submit buffer " << i);
			uint32_t size = wav.getSize();
			audio.appendBuffer(size);
			wav.read(audio.getBuffer(i), size);
			audio.submitBuffer(i, size);
		}

		wav.close();

		DMSG("sleep");
		Thread::sleep(10000);

		DMSG("stop");
		audio.stop();
	}
	catch (...)
	{
		std::cout << "error" << std::endl;
	}

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

	CoUninitialize();

	return 0;
}
Ejemplo n.º 4
0
int cui_main(int argc, char *argv[])
{
    uint32_t tid = syscall_mthread_create(inputLoop);
    struct audio_data_format defaultFormat = {0, 2, 16, 4400};
    Audio* audio = new Audio(&defaultFormat, AUDIO_OUTPUT);
    if (-1 == audio->start())
    {
        _printf("Can not connect to AUDIO server!\n");
    }

    strings oggFiles;
    if (strcmp(argv[1], "-d") == 0 && argc > 2)
    {
        listOggfiles(argv[2], oggFiles);
    }
    else
    {
        for (int i = 1; i < argc; i++)
        {
            oggFiles.push_back(argv[i]);
        }
    }

    for (int i = 0; i < oggFiles.size(); i++)
    {
        FILE* fp = fopen(oggFiles[i].data(), "rb");
        if (NULL == fp)
        {
            fprintf(stderr, "File open error: %s.\n", oggFiles[i].data());
            delete audio;
            return -1;
        }
        OggVorbis_File vf;
        if (ov_open(fp, &vf, NULL, 0) < 0)
        {
            fprintf(stderr, "Skipped, %s does not appear to be an Ogg bitstream.\n", argv[i]);
            continue;
        }
        char** infoTexts = ov_comment(&vf, -1)->user_comments;
        vorbis_info* vi=ov_info(&vf, -1);
        while(*infoTexts)
        {
            fprintf(stderr, "%s\n", *infoTexts);
            ++infoTexts;
        }
//         fprintf(stderr, "\nBitstream is %d channel, %dHz\n", vi->channels, vi->rate);
//         fprintf(stderr, "\nDecoded length: %d samples\n",(long)ov_pcm_total(&vf, -1));
//         fprintf(stderr, "Encoded by: %s\n\n", ov_comment(&vf, -1)->vendor);

        struct audio_data_format format = {0, vi->channels, 16, vi->rate};
        audio->setFormat(&format);
        int current_section;
        char pcmout[4096];
        fprintf(stdout, "key q(quit) <=(prev) =>(next)\n");
        for (;;)
        {
            switch(command)
            {
            case COMMAND_FORWARD:
                command = COMMAND_NONE;
                goto replay;
            case COMMAND_BACKWARD:
                command = COMMAND_NONE;
                i -= 2;
                goto replay;
            case COMMAND_EXIT:
                i = oggFiles.size();
                goto replay;
            case COMMAND_VOLUME_UP:
            case COMMAND_VOLUME_DOWN:
                break;
            default:
                break;
            }
            long ret = ov_read(&vf, pcmout, sizeof(pcmout), &current_section);
            if (ret == 0)
            {
                break;
            }
            else if (ret < 0)
            {
                fprintf(stderr, "Warning data broken? %s\n", argv[i]);
            }
            else
            {
                audio->write(pcmout, ret);
            }
        }
    replay:
        fclose(fp);
    }
    audio->stop();
    delete audio;
// cleanup causes crash!
//    ov_clear(&vf);
}