]> Johnzone git - FakeRadio.git/commitdiff
working mp3test
authorJohn Janus <mail@johnzone.org>
Fri, 15 Sep 2017 05:36:27 +0000 (07:36 +0200)
committerJohn Janus <mail@johnzone.org>
Fri, 15 Sep 2017 05:36:27 +0000 (07:36 +0200)
.gitignore [new file with mode: 0644]
.kdev4/FakeRadio.kdev4 [new file with mode: 0644]
FakeRadio.kdev4 [new file with mode: 0644]
Makefile
mp3player.c [new file with mode: 0644]
mp3player.h [new file with mode: 0644]
platt01.mp3 [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..874c63c
--- /dev/null
@@ -0,0 +1,2 @@
+*.o
+
diff --git a/.kdev4/FakeRadio.kdev4 b/.kdev4/FakeRadio.kdev4
new file mode 100644 (file)
index 0000000..5e23dcc
--- /dev/null
@@ -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 (file)
index 0000000..ee93349
--- /dev/null
@@ -0,0 +1,4 @@
+[Project]
+CreatedFrom=Makefile
+Manager=KDevCustomMakeManager
+Name=FakeRadio
index a02d4f66fd41ca7c4bba90d450a586995164868a..66bee6aaf9a1cf75a71e6ef52210e6aace4c2cd4 100644 (file)
--- 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 (file)
index 0000000..5c69abe
--- /dev/null
@@ -0,0 +1,66 @@
+#include "mp3player.h"
+#include <stdbool.h>
+#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 (file)
index 0000000..546d5c7
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef MP3PLAYER
+#define MP3PLAYER
+#include <pthread.h>
+#include <mpg123.h>
+#include <ao/ao.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+pthread_t startPlayThread(const char* file);
+
+void* playFunc(void* file);
+
+#endif
diff --git a/platt01.mp3 b/platt01.mp3
new file mode 100644 (file)
index 0000000..58a0121
Binary files /dev/null and b/platt01.mp3 differ