aboutsummaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-03-11 17:13:31 +1000
committerinmarket <andrewh@inmarket.com.au>2014-03-11 17:13:31 +1000
commitea5a1b849df6e5085a92957ad387f9e653674415 (patch)
tree72ede5ed78263a6fdba25039398b5c2a55bd1d3a /demos
parent944c33cbff5f2cfb1c80f48193aa2161574864fd (diff)
downloaduGFX-ea5a1b849df6e5085a92957ad387f9e653674415.tar.gz
uGFX-ea5a1b849df6e5085a92957ad387f9e653674415.tar.bz2
uGFX-ea5a1b849df6e5085a92957ad387f9e653674415.zip
Combine GAUDIN and GAUDOUT into a single GAUDIO module.
Simplify GAUDIN (now GAUDIO RECORD) api. Update audio demo's to match. Port Win32 driver to new audio api.
Diffstat (limited to 'demos')
-rw-r--r--demos/modules/gaudio/oscilloscope/demo.mk (renamed from demos/modules/audio/oscilloscope/demo.mk)2
-rw-r--r--demos/modules/gaudio/oscilloscope/gfxconf.h (renamed from demos/modules/audio/oscilloscope/gfxconf.h)5
-rw-r--r--demos/modules/gaudio/oscilloscope/gwinosc.c (renamed from demos/modules/audio/oscilloscope/gwinosc.c)175
-rw-r--r--demos/modules/gaudio/oscilloscope/gwinosc.h (renamed from demos/modules/audio/oscilloscope/gwinosc.h)8
-rw-r--r--demos/modules/gaudio/oscilloscope/main.c (renamed from demos/modules/audio/oscilloscope/main.c)12
-rw-r--r--demos/modules/gaudio/oscilloscope/results_264x264.jpg (renamed from demos/modules/audio/oscilloscope/results_264x264.jpg)bin19615 -> 19615 bytes
-rw-r--r--demos/modules/gaudio/play-wave/allwrong.wav (renamed from demos/modules/audio/play-wave/allwrong.wav)bin29434 -> 29434 bytes
-rw-r--r--demos/modules/gaudio/play-wave/demo.mk (renamed from demos/modules/audio/play-wave/demo.mk)2
-rw-r--r--demos/modules/gaudio/play-wave/gfxconf.h (renamed from demos/modules/audio/play-wave/gfxconf.h)5
-rw-r--r--demos/modules/gaudio/play-wave/main.c (renamed from demos/modules/audio/play-wave/main.c)12
-rw-r--r--demos/modules/gaudio/play-wave/romfs_allwrong.h (renamed from demos/modules/audio/play-wave/romfs_allwrong.h)2
-rw-r--r--demos/modules/gaudio/play-wave/romfs_files.h (renamed from demos/modules/audio/play-wave/romfs_files.h)0
12 files changed, 119 insertions, 104 deletions
diff --git a/demos/modules/audio/oscilloscope/demo.mk b/demos/modules/gaudio/oscilloscope/demo.mk
index ffdf6980..47b28f5f 100644
--- a/demos/modules/audio/oscilloscope/demo.mk
+++ b/demos/modules/gaudio/oscilloscope/demo.mk
@@ -1,3 +1,3 @@
-DEMODIR = $(GFXLIB)/demos/modules/audio/oscilloscope
+DEMODIR = $(GFXLIB)/demos/modules/gaudio/oscilloscope
GFXINC += $(DEMODIR)
GFXSRC += $(DEMODIR)/main.c $(DEMODIR)/gwinosc.c
diff --git a/demos/modules/audio/oscilloscope/gfxconf.h b/demos/modules/gaudio/oscilloscope/gfxconf.h
index 8733268d..2caa1da9 100644
--- a/demos/modules/audio/oscilloscope/gfxconf.h
+++ b/demos/modules/gaudio/oscilloscope/gfxconf.h
@@ -46,11 +46,14 @@
#define GFX_USE_GWIN TRUE
#define GFX_USE_GTIMER TRUE
//#define GFX_USE_GADC TRUE
-#define GFX_USE_GAUDIN TRUE
+#define GFX_USE_GAUDIO TRUE
/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_MULTITHREAD TRUE
+/* Features for the GAUDIO sub-system */
+#define GAUDIO_NEED_RECORD TRUE
+
#endif /* _GFXCONF_H */
diff --git a/demos/modules/audio/oscilloscope/gwinosc.c b/demos/modules/gaudio/oscilloscope/gwinosc.c
index 43ef1385..21a83760 100644
--- a/demos/modules/audio/oscilloscope/gwinosc.c
+++ b/demos/modules/gaudio/oscilloscope/gwinosc.c
@@ -32,8 +32,8 @@
*
* This GWIN superset implements a simple audio oscilloscope using the GAUDIN module.
*
- * It makes many assumptions, the most fundamental of which is that the audio device
- * produces unsigned integer samples.
+ * It makes many assumptions, the most fundamental of which is that the audio data
+ * should be scaled to SCOPE_Y_BITS.
*
* The GMISC module with GMISC_NEED_ARRAYOPS could be used to process the samples more
* correctly if we were really building something generic.
@@ -45,22 +45,15 @@
/* Include internal GWIN routines so we can build our own superset class */
#include "src/gwin/class_gwin.h"
-/* The size of our dynamically allocated audio buffer */
-#define AUDIOBUFSZ 64*2
-
/* How many flat-line sample before we trigger */
#define FLATLINE_SAMPLES 8
static void _destroy(GHandle gh) {
- gaudinStop();
+ gaudioRecordStop();
if (((GScopeObject *)gh)->lastscopetrace) {
gfxFree(((GScopeObject *)gh)->lastscopetrace);
((GScopeObject *)gh)->lastscopetrace = 0;
}
- if (((GScopeObject *)gh)->audiobuf) {
- gfxFree(((GScopeObject *)gh)->audiobuf);
- ((GScopeObject *)gh)->audiobuf = 0;
- }
}
static const gwinVMT scopeVMT = {
@@ -71,127 +64,136 @@ static const gwinVMT scopeVMT = {
0, // The after-clear routine
};
-GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency) {
+GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency, ArrayDataFormat format) {
+ /* Make sure the audio parameters are valid first */
+ if (!gaudioRecordInit(channel, frequency, format))
+ return 0;
+
/* Initialise the base class GWIN */
if (!(gs = (GScopeObject *)_gwindowCreate(g, &gs->g, pInit, &scopeVMT, 0)))
return 0;
/* Initialise the scope object members and allocate memory for buffers */
- gfxSemInit(&gs->bsem, 0, 1);
+ gs->format = format;
gs->nextx = 0;
if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(gs->g.width * sizeof(coord_t))))
return 0;
- if (!(gs->audiobuf = (audin_sample_t *)gfxAlloc(AUDIOBUFSZ * sizeof(audin_sample_t))))
- return 0;
-#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
- gs->lasty = gs->g.height/2;
-#elif TRIGGER_METHOD == TRIGGER_MINVALUE
- gs->lasty = gs->g.height/2;
- gs->scopemin = 0;
-#endif
-
- /* Start the GADC high speed converter */
- gaudinInit(channel, frequency, gs->audiobuf, AUDIOBUFSZ, AUDIOBUFSZ/2);
- gaudinSetBSem(&gs->bsem, &gs->myEvent);
- gaudinStart();
+ #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
+ gs->lasty = gs->g.height/2;
+ #elif TRIGGER_METHOD == TRIGGER_MINVALUE
+ gs->lasty = gs->g.height/2;
+ gs->scopemin = 0;
+ #endif
+ /* Set visibility */
gwinSetVisible((GHandle)gs, pInit->show);
+
+ /* Start the audio recording */
+ gaudioRecordStart();
+
return (GHandle)gs;
}
void gwinScopeWaitForTrace(GHandle gh) {
#define gs ((GScopeObject *)(gh))
+ GAudioData *paud;
int i;
coord_t x, y;
coord_t yoffset;
- audin_sample_t *pa;
+ uint8_t *pa8;
+ uint16_t *pa16;
coord_t *pc;
-#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
- bool_t rdytrigger;
- int flsamples;
-#elif TRIGGER_METHOD == TRIGGER_MINVALUE
- bool_t rdytrigger;
- int flsamples;
- coord_t scopemin;
-#endif
+ uint8_t shr;
+
+ #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
+ bool_t rdytrigger;
+ int flsamples;
+ #elif TRIGGER_METHOD == TRIGGER_MINVALUE
+ bool_t rdytrigger;
+ int flsamples;
+ coord_t scopemin;
+ #endif
if (gh->vmt != &scopeVMT)
return;
/* Wait for a set of audio conversions */
- gfxSemWait(&gs->bsem, TIME_INFINITE);
+ paud = gaudioRecordGetData(TIME_INFINITE);
/* Ensure we are drawing in the right area */
#if GDISP_NEED_CLIP
gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height);
#endif
+ shr = 16 - gfxSampleFormatBits(gs->format);
yoffset = gh->height/2;
- if (!(GAUDIN_SAMPLE_FORMAT & 1))
+ if (!gfxSampleFormatIsSigned(gs->format))
yoffset += (1<<SCOPE_Y_BITS)/2;
+
x = gs->nextx;
pc = gs->lastscopetrace+x;
- pa = gs->myEvent.buffer;
-#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
- rdytrigger = FALSE;
- flsamples = 0;
-#elif TRIGGER_METHOD == TRIGGER_MINVALUE
- rdytrigger = FALSE;
- flsamples = 0;
- scopemin = 0;
-#endif
+ pa8 = (uint8_t *)(paud+1);
+ pa16 = (uint16_t *)(paud+1);
+
+ #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
+ rdytrigger = FALSE;
+ flsamples = 0;
+ #elif TRIGGER_METHOD == TRIGGER_MINVALUE
+ rdytrigger = FALSE;
+ flsamples = 0;
+ scopemin = 0;
+ #endif
- for(i = gs->myEvent.count; i; i--) {
+ for(i = paud->len/(gfxSampleFormatBits(gs->format)/8); i; i--) {
/* Calculate the new scope value - re-scale using simple shifts for efficiency, re-center and y-invert */
- #if GAUDIN_BITS_PER_SAMPLE > SCOPE_Y_BITS
- y = yoffset - (*pa++ >> (GAUDIN_BITS_PER_SAMPLE - SCOPE_Y_BITS));
- #else
- y = yoffset - (*pa++ << (SCOPE_Y_BITS - GAUDIN_BITS_PER_SAMPLE));
+ if (gs->format <= 8)
+ y = yoffset - (((coord_t)(*pa8++ ) << shr) >> (16-SCOPE_Y_BITS));
+ else
+ y = yoffset - (((coord_t)(*pa16++) << shr) >> (16-SCOPE_Y_BITS));
+
+ #if TRIGGER_METHOD == TRIGGER_MINVALUE
+ /* Calculate the scopemin ready for the next trace */
+ if (y > scopemin)
+ scopemin = y;
#endif
-#if TRIGGER_METHOD == TRIGGER_MINVALUE
- /* Calculate the scopemin ready for the next trace */
- if (y > scopemin)
- scopemin = y;
-#endif
-
/* Have we reached the end of a scope trace? */
if (x >= gh->width) {
-#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP || TRIGGER_METHOD == TRIGGER_MINVALUE
- /* Handle triggering - we trigger on the next sample minimum (y value maximum) or a flat-line */
-
- #if TRIGGER_METHOD == TRIGGER_MINVALUE
- /* Arm when we reach the sample minimum (y value maximum) of the previous trace */
- if (!rdytrigger && y >= gs->scopemin)
- rdytrigger = TRUE;
- #endif
+ #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP || TRIGGER_METHOD == TRIGGER_MINVALUE
+ /* Handle triggering - we trigger on the next sample minimum (y value maximum) or a flat-line */
- if (y == gs->lasty) {
- /* Trigger if we get too many flat-line samples regardless of the armed state */
- if (++flsamples < FLATLINE_SAMPLES)
- continue;
- flsamples = 0;
- } else if (y > gs->lasty) {
- gs->lasty = y;
- flsamples = 0;
- #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
- /* Arm the trigger when samples fall (y increases) ie. negative slope */
- rdytrigger = TRUE;
+ #if TRIGGER_METHOD == TRIGGER_MINVALUE
+ /* Arm when we reach the sample minimum (y value maximum) of the previous trace */
+ if (!rdytrigger && y >= gs->scopemin)
+ rdytrigger = TRUE;
#endif
- continue;
- } else {
- /* If the trigger is armed, Trigger when samples increases (y decreases) ie. positive slope */
- gs->lasty = y;
- flsamples = 0;
- if (!rdytrigger)
- continue;
- }
- /* Ready for a the next trigger cycle */
- rdytrigger = FALSE;
-#endif
+ if (y == gs->lasty) {
+ /* Trigger if we get too many flat-line samples regardless of the armed state */
+ if (++flsamples < FLATLINE_SAMPLES)
+ continue;
+ flsamples = 0;
+ } else if (y > gs->lasty) {
+ gs->lasty = y;
+ flsamples = 0;
+ #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
+ /* Arm the trigger when samples fall (y increases) ie. negative slope */
+ rdytrigger = TRUE;
+ #endif
+ continue;
+ } else {
+ /* If the trigger is armed, Trigger when samples increases (y decreases) ie. positive slope */
+ gs->lasty = y;
+ flsamples = 0;
+ if (!rdytrigger)
+ continue;
+ }
+
+ /* Ready for a the next trigger cycle */
+ rdytrigger = FALSE;
+ #endif
/* Prepare for a scope trace */
x = 0;
@@ -214,5 +216,6 @@ void gwinScopeWaitForTrace(GHandle gh) {
gs->scopemin = scopemin;
#endif
+ gaudioReleaseBuffer(paud);
#undef gs
}
diff --git a/demos/modules/audio/oscilloscope/gwinosc.h b/demos/modules/gaudio/oscilloscope/gwinosc.h
index 0efb403c..5a5c5034 100644
--- a/demos/modules/audio/oscilloscope/gwinosc.h
+++ b/demos/modules/gaudio/oscilloscope/gwinosc.h
@@ -64,9 +64,7 @@ typedef struct GScopeObject_t {
GWindowObject g; // Base Class
coord_t *lastscopetrace; // To store last scope trace
- gfxSem bsem; // We get signalled on this
- audin_sample_t *audiobuf; // To store audio samples
- GEventAudioIn myEvent; // Information on received samples
+ ArrayDataFormat format; // The sample format
coord_t nextx; // Where we are up to
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
coord_t lasty; // The last y value - used for trigger slope detection
@@ -83,8 +81,8 @@ extern "C" {
/**
* Create a scope window.
*/
- GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency);
- #define gwinScopeCreate(gs,pI,ch,f) gwinGScopeCreate(GDISP,gs,pI,ch,f)
+ GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency, ArrayDataFormat format);
+ #define gwinScopeCreate(gs,pI,ch,f,fmt) gwinGScopeCreate(GDISP,gs,pI,ch,f,fmt)
/**
* Wait for a scope trace to be ready and then draw it.
diff --git a/demos/modules/audio/oscilloscope/main.c b/demos/modules/gaudio/oscilloscope/main.c
index 32418450..b44b5a02 100644
--- a/demos/modules/audio/oscilloscope/main.c
+++ b/demos/modules/gaudio/oscilloscope/main.c
@@ -39,8 +39,9 @@
#include "gwinosc.h"
/* Specify our timing parameters */
-#define MY_AUDIO_FREQUENCY 4000 /* 4khz */
-#define MY_AUDIO_CHANNEL 0 /* Use channel 0 */
+#define MY_AUDIO_FREQUENCY 8000 /* 8khz. If this is too much try 4000 (4khz) */
+#define MY_AUDIO_CHANNEL 0 /* Use channel 0 - must be a mono channel */
+#define MY_AUDIO_FORMAT GAUDIO_RECORD_FORMAT1 /* The default format */
/* Data */
static GScopeObject gScopeWindow;
@@ -54,6 +55,11 @@ int main(void) {
gfxInit();
+ // Allocate audio buffers - 4 x 128 byte buffers.
+ // You may need to increase this for slower cpu's.
+ // You may be able to decrease this for low latency operating systems.
+ gaudioAllocBuffers(4, 128);
+
/* Get the screen dimensions */
swidth = gdispGetWidth();
sheight = gdispGetHeight();
@@ -65,7 +71,7 @@ int main(void) {
wi.show = TRUE;
wi.x = wi.y = 0;
wi.width = swidth; wi.height = sheight;
- ghScope = gwinScopeCreate(&gScopeWindow, &wi, MY_AUDIO_CHANNEL, MY_AUDIO_FREQUENCY);
+ ghScope = gwinScopeCreate(&gScopeWindow, &wi, MY_AUDIO_CHANNEL, MY_AUDIO_FREQUENCY, MY_AUDIO_FORMAT);
}
gwinSetBgColor(ghScope, White);
gwinSetColor(ghScope, Red);
diff --git a/demos/modules/audio/oscilloscope/results_264x264.jpg b/demos/modules/gaudio/oscilloscope/results_264x264.jpg
index e459f7e1..e459f7e1 100644
--- a/demos/modules/audio/oscilloscope/results_264x264.jpg
+++ b/demos/modules/gaudio/oscilloscope/results_264x264.jpg
Binary files differ
diff --git a/demos/modules/audio/play-wave/allwrong.wav b/demos/modules/gaudio/play-wave/allwrong.wav
index e221ff2f..e221ff2f 100644
--- a/demos/modules/audio/play-wave/allwrong.wav
+++ b/demos/modules/gaudio/play-wave/allwrong.wav
Binary files differ
diff --git a/demos/modules/audio/play-wave/demo.mk b/demos/modules/gaudio/play-wave/demo.mk
index 242e57b5..cd6f941f 100644
--- a/demos/modules/audio/play-wave/demo.mk
+++ b/demos/modules/gaudio/play-wave/demo.mk
@@ -1,3 +1,3 @@
-DEMODIR = $(GFXLIB)/demos/modules/audio/play-wave
+DEMODIR = $(GFXLIB)/demos/modules/gaudio/play-wave
GFXINC += $(DEMODIR)
GFXSRC += $(DEMODIR)/main.c
diff --git a/demos/modules/audio/play-wave/gfxconf.h b/demos/modules/gaudio/play-wave/gfxconf.h
index 1480b919..a9bb6252 100644
--- a/demos/modules/audio/play-wave/gfxconf.h
+++ b/demos/modules/gaudio/play-wave/gfxconf.h
@@ -43,7 +43,7 @@
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
-#define GFX_USE_GAUDOUT TRUE
+#define GFX_USE_GAUDIO TRUE
#define GFX_USE_GFILE TRUE
/* Features for the GDISP sub-system. */
@@ -53,6 +53,9 @@
/* GDISP fonts to include */
#define GDISP_INCLUDE_FONT_UI2 TRUE
+/* Features for the GAUDIO sub-system */
+#define GAUDIO_NEED_PLAY TRUE
+
/* Features for the GFILE sub-system */
#define GFILE_NEED_ROMFS TRUE
diff --git a/demos/modules/audio/play-wave/main.c b/demos/modules/gaudio/play-wave/main.c
index e8cab254..f15ec7a1 100644
--- a/demos/modules/audio/play-wave/main.c
+++ b/demos/modules/gaudio/play-wave/main.c
@@ -34,8 +34,8 @@
#include "gfx.h"
/* Specify our timing parameters */
-#define MY_AUDIO_CHANNEL 0 /* Use channel 0 */
-#define MY_AUDIO_CHANNEL_IS_STEREO GAUDOUT_CHANNEL0_STEREO /* Is it stereo? */
+#define MY_AUDIO_CHANNEL 0 /* Use channel 0 */
+#define MY_AUDIO_CHANNEL_IS_STEREO GAUDOUT_CHANNEL0_IS_STEREO /* Is it stereo? */
// Storage for the wave header
static char whdr[32];
@@ -61,7 +61,9 @@ int main(void) {
// Any font will do
font = gdispOpenFont("*");
- // Allocate audio buffers - 4 x 512 byte buffers. You may need to increase this for slower cpu's.
+ // Allocate audio buffers - 4 x 512 byte buffers.
+ // You may need to increase this for slower cpu's.
+ // You may be able to decrease this for low latency operating systems.
if (!gaudioAllocBuffers(4, 512)) {
errmsg = "Err: No Memory";
goto theend;
@@ -179,8 +181,8 @@ int main(void) {
}
gfileClose(f);
- // Wait 3 seconds for the play to finish - FIX THIS
- gfxSleepMilliseconds(3000);
+ // Wait for the play to finish
+ gaudioPlayWait(TIME_INFINITE);
gdispDrawString(0, gdispGetHeight()/2+10, "Done", font, Green);
// The end
diff --git a/demos/modules/audio/play-wave/romfs_allwrong.h b/demos/modules/gaudio/play-wave/romfs_allwrong.h
index a374bde3..adc74fc7 100644
--- a/demos/modules/audio/play-wave/romfs_allwrong.h
+++ b/demos/modules/gaudio/play-wave/romfs_allwrong.h
@@ -1,7 +1,7 @@
/**
* This file was generated from "allwrong.wav" using...
*
- * file2c -bcs allwrong.wav romfs_allwrong.h
+ * file2c -dcs allwrong.wav romfs_allwrong.h
*
*/
static const char allwrong[] = {
diff --git a/demos/modules/audio/play-wave/romfs_files.h b/demos/modules/gaudio/play-wave/romfs_files.h
index db3e5491..db3e5491 100644
--- a/demos/modules/audio/play-wave/romfs_files.h
+++ b/demos/modules/gaudio/play-wave/romfs_files.h