From: John Janus Date: Fri, 15 Sep 2017 05:36:27 +0000 (+0200) Subject: working mp3test X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=cdc8b39700180a5ef0a96012350e91e388900cf6;p=FakeRadio.git working mp3test --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..874c63c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o + diff --git a/.kdev4/FakeRadio.kdev4 b/.kdev4/FakeRadio.kdev4 new file mode 100644 index 0000000..5e23dcc --- /dev/null +++ b/.kdev4/FakeRadio.kdev4 @@ -0,0 +1,24 @@ +[Buildset] +BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x12\x00F\x00a\x00k\x00e\x00R\x00a\x00d\x00i\x00o) + +[Cppcheck] +checkInformation=true +checkMissingInclude=true +checkPerformance=true +checkStyle=true +checkUnusedFunction=true + +[CustomDefinesAndIncludes][ProjectPath0] +Path=. +parseAmbiguousAsCPP=true +parserArguments=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 +parserArgumentsC=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=gnu11 + +[CustomDefinesAndIncludes][ProjectPath0][Compiler] +Name=GCC + +[CustomDefinesAndIncludes][ProjectPath0][Includes] +1=/home/john/devel/RPi/wiringPi/wiringPi/ + +[Project] +VersionControlSupport=kdevgit diff --git a/FakeRadio.kdev4 b/FakeRadio.kdev4 new file mode 100644 index 0000000..ee93349 --- /dev/null +++ b/FakeRadio.kdev4 @@ -0,0 +1,4 @@ +[Project] +CreatedFrom=Makefile +Manager=KDevCustomMakeManager +Name=FakeRadio diff --git a/Makefile b/Makefile index a02d4f6..66bee6a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ CC = gcc CFLAGS = -std=gnu11 -Wall -LDFLAGS = -lwiringPi -lpthread +LDFLAGS = -lpthread -lao -lmpg123 fakeradio: simple_try.c $(CC) $(CFLAGS) -o ledtest simple_try.c $(LDFLAGS) +mp3player.o: mp3player.h mp3player.c + $(CC) $(CFLAGS) -o mp3player.o mp3player.c $(LDFLAGS) + +mp3test: mp3player.o + $(CC) $(CFLAGS) -o mp3test mp3player.o $(LDFLAGS) diff --git a/mp3player.c b/mp3player.c new file mode 100644 index 0000000..5c69abe --- /dev/null +++ b/mp3player.c @@ -0,0 +1,66 @@ +#include "mp3player.h" +#include +#define BITS 8 + +pthread_t startPlayThread(const char* file) +{ + pthread_t thread; + pthread_create(&thread, NULL, playFunc, (void*) file); + return thread; +} + +void* playFunc(void* file) +{ + bool running = true; + mpg123_handle* mh; + unsigned char* buffer; + size_t buffer_size; + size_t done; + int err; + + int driver; + ao_device* aodev; + ao_sample_format format; + int channels; + int encoding; + long rate; + + ao_initialize(); + driver = ao_default_driver_id(); + mpg123_init(); + mh = mpg123_new(NULL, &err); + buffer_size = mpg123_outblock(mh); + buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char)); + + if (mpg123_open(mh, file) != MPG123_OK) return; + if (mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK) return; + + format.bits = mpg123_encsize(encoding) * BITS; + format.rate = rate; + format.channels = channels; + format.byte_format = AO_FMT_NATIVE; + format.matrix = 0; + aodev = ao_open_live(driver, &format, NULL); + + while (mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK && running) { + ao_play(aodev, buffer, done); + } + + // cleanup + free (buffer); + ao_close(aodev); + mpg123_close(mh); + mpg123_delete(mh); + mpg123_exit(); + ao_shutdown(); + +} + +int main (int argc, char** argv) +{ + pthread_t thread = startPlayThread("platt01.mp3"); + void* status; + pthread_join(thread, status); + //playFunc("platt01.mp3"); +} + diff --git a/mp3player.h b/mp3player.h new file mode 100644 index 0000000..546d5c7 --- /dev/null +++ b/mp3player.h @@ -0,0 +1,13 @@ +#ifndef MP3PLAYER +#define MP3PLAYER +#include +#include +#include +#include +#include + +pthread_t startPlayThread(const char* file); + +void* playFunc(void* file); + +#endif diff --git a/platt01.mp3 b/platt01.mp3 new file mode 100644 index 0000000..58a0121 Binary files /dev/null and b/platt01.mp3 differ