I want to decode a mp3
file to pcm
:
#include <iostream>
#include <mpg123.h>
#include <out123.h>
using namespace std;
int main()
{
mpg123_handle *mh;
unsigned char *buffer;
size_t buffer_size;
size_t done;
int err;
int channels, encoding;
long rate;
buffer_size = mpg123_outblock(mh);
buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));
mpg123_init();
mh = mpg123_new(NULL, &err);
mpg123_open(mh, "/home/abbas/Desktop/nastaran.mp3");
// mpg123_getformat(mh, &rate, &channels, &encoding);
while (mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK)
cout << buffer ;
free(buffer);
mpg123_close(mh);
mpg123_delete(mh);
mpg123_exit();
return 0;
}
But it gives me this error:
The program has unexpectedly finished.
This error says nothing about the reason. Where is the problem?
Is it something about the OS?
cmake file:
project(echoprint2)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
add_library(mpg123 SHARED IMPORTED )
set_target_properties(mpg123 PROPERTIES IMPORTED_LOCATION /usr/local /lib/libmpg123.so)
TARGET_LINK_LIBRARIES(echoprint2 mpg123)
I fixed some errors and got some numeric values to be produced. I leave it to you to check if the waveform produced is correct. Suggest using Excel and Audacity to visualize it and confirm that the waveforms look alright.