demOS
 All Data Structures Files Modules Pages
SOUND.H
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------ -----------------
2  Copyright J.Hubert 2015
3 
4  This file is part of demOS
5 
6  demOS is free software: you can redistribute it and/or modify it under the terms of
7  the GNU Lesser General Public License as published by the Free Software Foundation,
8  either version 3 of the License, or (at your option) any later version.
9 
10  demOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
11  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  See the GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License along with demOS.
15  If not, see <http://www.gnu.org/licenses/>.
16 ------------------------------------------------------------------------------------------------- */
17 
36 #ifndef SOUND_H
37 #define SOUND_H
38 
39 #include "DEMOSDK\BASTYPES.H"
40 #include "DEMOSDK\HARDWARE.H"
41 #include "DEMOSDK\ALLOC.H"
42 #include "DEMOSDK\LOAD.H"
43 
44 extern volatile u8 SNDleftVolume;
45 extern volatile u8 SNDrightVolume;
46 extern volatile s8 SNDfademasterVolume;
47 extern volatile u8 SNDspeedfade;
48 extern volatile u16 SNDdmaLoopCount;
49 extern void* SNDsourceTransfer;
50 extern volatile void* SNDendSourceTransfer;
51 extern void* SNDdestTransfer;
52 
53 extern volatile void* SNDlastDMAposition; /* read only */
54 extern volatile s8 SNDmasterVolume; /* ready only - debug purpose */
55 
56 STRUCT(SNDcore)
57 {
58  u8* dmaBuffer;
59  u8* cache;
60  u32 sampleLength;
61 
62  bool pcmLoaded;
63  bool syncWithSoundtrack;
64 
65  LOADrequest* currentLoadRequest;
66  u16 dmaLoopstart;
67 
68  volatile s16 playerContext;
69  u16 playerStart;
70  volatile u16 playerClientStep;
71 };
72 
73 #ifndef SOUND_C
74 
75 extern SNDcore snd;
76 extern u8 SNDchannelVolume[];
77 
78 #endif
79 
80 #define SND_BEGIN case 0: snd.playerStart = __LINE__;
81 
82 #define SND_LOADSAMPLE(MEDIA,RESOURCE) snd.currentLoadRequest = LOADrequestLoad(&RSC_##MEDIA##, RSC_##MEDIA##_ZIK__##RESOURCE##_RAW, snd.cache, LOAD_PRIOTITY_HIGH);
83 #define SND_WAIT_SAMPLELOADED case __LINE__: if ( snd.currentLoadRequest->processed == false ) return __LINE__; snd.currentLoadRequest->allocated = false; snd.currentLoadRequest = NULL;
84 
85 #define SND_SYNC_COPYCACHE_TO_LEFT(OFFSET,LEN) SNDcopySample(snd.cache, snd.dmaBuffer + (OFFSET << 1) , LEN);
86 #define SND_SYNC_COPYCACHE_TO_RIGHT(OFFSET,LEN) SNDcopySample(snd.cache, snd.dmaBuffer + (OFFSET << 1) +1 , LEN);
87 
88 #define SND_COPYCACHE_TO_LEFT(OFFSET,LEN) SNDsourceTransfer = snd.cache; SNDendSourceTransfer = snd.cache + LEN; SNDdestTransfer = snd.dmaBuffer + (OFFSET << 1);
89 #define SND_COPYCACHE_TO_RIGHT(OFFSET,LEN) SNDsourceTransfer = snd.cache; SNDendSourceTransfer = snd.cache + LEN; SNDdestTransfer = snd.dmaBuffer + (OFFSET << 1) + 1;
90 #define SND_WAIT_CACHECOPIED case __LINE__: if ( SNDsourceTransfer < SNDendSourceTransfer ) return __LINE__;
91 
92 #define SND_VOLUME_SET(VOL) SNDmasterVolume = VOL; (*HW_MICROWIRE_MASK) = HW_MICROWIRE_MASK_SOUND; (*HW_MICROWIRE_DATA) = HW_MICROWIRE_VOLUME | VOL;
93 #define SND_VOLUME_FADEIN(STEP) SNDspeedfade = STEP; SNDmasterVolume = 0; SNDfademasterVolume = 1;
94 #define SND_VOLUME_FADEOUT(STEP) SNDspeedfade = STEP; SNDmasterVolume = 40; SNDfademasterVolume = -1;
95 
96 #define SND_SETPANNING(PAN) SNDleftVolume = SNDchannelVolume[PAN]; SNDrightVolume = SNDchannelVolume[6 - PAN]; { STATIC_ASSERT(PAN<7); }
97 
98 #define SND_DMALOOP_RESET snd.dmaLoopstart = SNDdmaLoopCount;
99 #define SND_WAIT_DMALOOP_REACH(COUNT) case __LINE__: if ( (SNDdmaLoopCount - snd.dmaLoopstart) < COUNT ) return __LINE__;
100 
101 #define SND_IDLE case __LINE__: return __LINE__;
102 #define SND_RESTART return 0;
103 #define SND_WAIT_CLIENTSTEP(COUNT) case __LINE__: if (( snd.playerClientStep < COUNT ) && snd.syncWithSoundtrack ) return __LINE__;
104 
105 void SNDinit (RINGallocator* _allocator, u32 _sampleLen);
106 void SNDshutdown (RINGallocator* _allocator);
107 void SNDcopySample (u8* _source, u8* _dest, u32 _length);
108 void SNDwaitDMALoop (void);
109 void SNDwaitClientStep(u16 _clientStep); /* shoud be used from idle thread only ! */
110 void SNDplayNoise (u16 _freq, u16 _level);
111 void SNDstopNoise (void);
112 
113 #ifdef DEMOS_DEBUG
114 u16 SNDtrace (void* _image, u16 _pitch, u16 _planePitch, u16 _y);
115 #endif
116 
117 #endif
LOAD
Definition: ALLOC.H:40
HARDWARE
RING
BASTYPES
Definition: SOUND.H:56
Definition: LOAD.H:101