Part of MicroGen4 Music Synthesizer Program. (But not test it yet.) I2S ,DMA ,Stereo ,16Bit Dac(PCM1781) See detail: http://www.geocities.jp/micro_diys/index2
Now added generate Saw Wave to DAC function in generate(); You will hear Stereo saw wave sound now.
more info: http://www.geocities.jp/micro_diys/i2s_test_sample/i2s_test_sample.html
Synthesizer.cpp@1:48f506a7b488, 2017-09-21 (annotated)
- Committer:
- p_igmon
- Date:
- Thu Sep 21 10:20:50 2017 +0000
- Revision:
- 1:48f506a7b488
- Parent:
- 0:dc88722ab141
Added Sample Saw Wave in Function Generate.
; DAC PCM1781 Can Output Saw Wave now.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p_igmon | 0:dc88722ab141 | 1 | /* |
p_igmon | 0:dc88722ab141 | 2 | COPYRIGHT(c) 2014 p.igmon |
p_igmon | 0:dc88722ab141 | 3 | */ |
p_igmon | 0:dc88722ab141 | 4 | |
p_igmon | 0:dc88722ab141 | 5 | #include "synthesizer.h" |
p_igmon | 0:dc88722ab141 | 6 | |
p_igmon | 0:dc88722ab141 | 7 | /* DMA WAVE BUFFER */ |
p_igmon | 0:dc88722ab141 | 8 | extern S16 DMA_Buffer[]; |
p_igmon | 0:dc88722ab141 | 9 | extern __IO BUFFER_StateTypeDef BufferOffset; |
p_igmon | 0:dc88722ab141 | 10 | |
p_igmon | 0:dc88722ab141 | 11 | void wave_generate(void){ |
p_igmon | 1:48f506a7b488 | 12 | u16 count; |
p_igmon | 1:48f506a7b488 | 13 | s16 rch,lch;// 16bit stereo |
p_igmon | 1:48f506a7b488 | 14 | volatile s16 *ptr0; |
p_igmon | 0:dc88722ab141 | 15 | |
p_igmon | 1:48f506a7b488 | 16 | if (bufferoffset == dma_fullcomplete){ |
p_igmon | 1:48f506a7b488 | 17 | ptr0 = (s16 *)&dma_buffer[dma_buffersize>>1];// from half |
p_igmon | 0:dc88722ab141 | 18 | }else{ |
p_igmon | 1:48f506a7b488 | 19 | ptr0 = (s16 *)&dma_buffer[0];// from top |
p_igmon | 0:dc88722ab141 | 20 | } |
p_igmon | 1:48f506a7b488 | 21 | bufferoffset = dma_idle; |
p_igmon | 0:dc88722ab141 | 22 | |
p_igmon | 1:48f506a7b488 | 23 | count = dma_buffersize>>2;// 512samples |
p_igmon | 0:dc88722ab141 | 24 | while(count-- > 0){ |
p_igmon | 0:dc88722ab141 | 25 | |
p_igmon | 0:dc88722ab141 | 26 | /* generate wave here */ |
p_igmon | 1:48f506a7b488 | 27 | lch = ((s16)(count - 256))<<6;// Saw Wave Lch |
p_igmon | 1:48f506a7b488 | 28 | rch = ((s16)(256 -count))<<6;// Saw Wave Rch |
p_igmon | 0:dc88722ab141 | 29 | *ptr0++ = lch; |
p_igmon | 0:dc88722ab141 | 30 | *ptr0++ = rch; |
p_igmon | 0:dc88722ab141 | 31 | } |
p_igmon | 0:dc88722ab141 | 32 | } |