Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int playPCM(string thePath)
- {
- mpg123_handle *mh;
- unsigned char *buffer = new char unsigned[32];
- size_t buffer_size;
- size_t done;
- int err;
- int driver;
- ao_device *dev;
- ao_sample_format format;
- int channels, encoding;
- long rate;
- /* initializations */
- ao_initialize();
- driver = ao_default_driver_id();
- mpg123_init();
- mh = mpg123_new(NULL, &err);
- buffer_size = mpg123_outblock(mh);
- /* open the file and get the decoding format */
- mpg123_open(mh, thePath.c_str());
- mpg123_getformat(mh, &rate, &channels, &encoding);
- /* set the output format and open the output device */
- format.bits = mpg123_encsize(encoding) * BITS;
- format.rate = rate;
- format.channels = channels;
- format.byte_format = AO_FMT_NATIVE;
- format.matrix = 0;
- dev = ao_open_live(driver, &format, NULL);
- //char *workAround = new char[buffer_size * sizeof(unsigned char)];
- char *workAround = new char[32];
- /* decode and play */
- std::ofstream out("raw", ios::binary);
- while (mpg123_read(mh, buffer, 32, &done) == MPG123_OK)
- {
- for (auto i = 0; i != 32; i++)
- {
- workAround[i] = static_cast<char>(buffer[i]);
- buffer[i] = '\0';
- }
- out << workAround;
- // This is the output of the pcm data
- }
- free(buffer);
- ao_close(dev);
- mpg123_close(mh);
- mpg123_delete(mh);
- mpg123_exit();
- ao_shutdown();
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement