Changeset 352 for CoolAudio/Systems
- Timestamp:
- Apr 23, 2012, 1:32:52 PM (13 years ago)
- Location:
- CoolAudio/Systems
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolAudio/Systems/DSP/UAudioSystemDSP.pas
r348 r352 1 1 unit UAudioSystemDSP; 2 2 3 {$I UCoolAudioConfig.inc} 3 4 {$mode delphi}{$H+} 4 5 5 6 interface 6 7 7 //{$IFDEF AudioSystemDSP}8 {$IFDEF AudioSystemDSP} 8 9 uses 9 Classes, SysUtils, UAudioSystem, BaseUnix ;10 Classes, SysUtils, UAudioSystem, BaseUnix, UWavFile, StdCtrls, ExtCtrls; 10 11 11 12 type … … 17 18 FDeviceId: Integer; 18 19 public 20 Channels: Integer; 21 SampleRate: Integer; // Hz 22 BitsPerSample: Integer; 19 23 procedure OpenDevice; 24 procedure CloseDevice; 25 constructor Create(AOwner: TComponent); override; 26 destructor Destroy; override; 20 27 end; 21 28 … … 23 30 24 31 TPlayerDSP = class(TPlayer) 32 private 33 FTimer: TTimer; 34 procedure TimerExecute(Sender: TObject); 25 35 public 36 WavFile: TWAVFile; 26 37 procedure Play; override; 27 38 procedure Pause; override; 28 39 procedure Stop; override; 40 procedure Open; override; 41 procedure Close; override; 42 constructor Create(AOwner: TComponent); override; 43 destructor Destroy; override; 29 44 end; 30 45 31 //{$ENDIF} 46 const 47 BUFFERLEN = 1024; 48 49 const 50 { Values obtained from a C program - These are complex (!) C macros } 51 SNDCTL_DSP_STEREO = -1073459197; 52 SNDCTL_DSP_RESET = 20480; 53 SNDCTL_DSP_SYNC = 20481; 54 SOUND_PCM_WRITE_BITS = -1073459195; 55 SOUND_PCM_WRITE_CHANNELS = -1073459194; 56 SOUND_PCM_WRITE_RATE = -1073459198; 57 58 resourcestring 59 SPlaying = 'Playing : '; 60 SErrChannels = 'Error : Number of channels not supported: '; 61 SErrOpeningDevice = 'Could not open sound device'; 62 SErrSettingStereo = 'Could not set stereo'; 63 SErrResettingDevice = 'Could not reset DSP device'; 64 SErrSetWriteBits = 'Could not set write bits to 16'; 65 SErrSetChannels = 'Could not set channels'; 66 SErrSetSampleRate = 'Could not set sync mode'; 67 SErrSetSyncMode = 'Could not set sync mode'; 68 69 {$ENDIF} 32 70 33 71 implementation 72 73 {$IFDEF AudioSystemDSP} 34 74 35 75 { TAudioSystemDSP } … … 37 77 procedure TAudioSystemDSP.OpenDevice; 38 78 var 39 fd, Stereo, Temp, Error: Longint;79 Stereo, Error: Longint; 40 80 begin 41 fd := fpOpen('/dev/dsp', O_WRONLY, 0); 42 if fd < 0 then 43 PlayError(SErrOpeningDevice); 81 Write('Openning /dev/dsp'); 82 FDeviceId := fpOpen('/dev/dsp', O_WRONLY, 0); 83 if FDeviceId < 0 then 84 raise Exception.Create(SErrOpeningDevice); 44 85 Stereo := 0; 45 if not (FpIOCtl(fd, SNDCTL_DSP_STEREO, @Stereo) <> -1) then 46 PlayError(SErrSettingStereo); 47 if not (FpIOCtl(fd, SNDCTL_DSP_RESET, nil) <> -1) then 48 PlayError(SErrResettingDevice); 49 Temp := 16; 50 if not (FpIOCtl(fd, SOUND_PCM_WRITE_BITS, @Temp) <> -1) then 51 PlayError(SErrSetWriteBits); 52 if not (FpIOCtl(fd, SOUND_PCM_WRITE_CHANNELS, @Channels) <> -1) then 53 PlayError(SErrSetChannels); 54 if not (FpIOCtl(fd, SOUND_PCM_WRITE_RATE, @SampleRate) <> -1) then 55 PlayError(SErrSetSampleRate); 56 if not (FpIOCtl(fd, SNDCTL_DSP_SYNC, nil) <> -1) then 57 PlayError(SErrSetSyncMode); 58 FDeviceId := Fd; 86 if not (FpIOCtl(FDeviceId, SNDCTL_DSP_STEREO, @Stereo) <> -1) then 87 raise Exception.Create(SErrSettingStereo); 88 if not (FpIOCtl(FDeviceId, SNDCTL_DSP_RESET, nil) <> -1) then 89 raise Exception.Create(SErrResettingDevice); 90 if not (FpIOCtl(FDeviceId, SOUND_PCM_WRITE_BITS, @BitsPerSample) <> -1) then 91 raise Exception.Create(SErrSetWriteBits); 92 if not (FpIOCtl(FDeviceId, SOUND_PCM_WRITE_CHANNELS, @Channels) <> -1) then 93 raise Exception.Create(SErrSetChannels); 94 if not (FpIOCtl(FDeviceId, SOUND_PCM_WRITE_RATE, @SampleRate) <> -1) then 95 raise Exception.Create(SErrSetSampleRate); 96 if not (FpIOCtl(FDeviceId, SNDCTL_DSP_SYNC, nil) <> -1) then 97 raise Exception.Create(SErrSetSyncMode); 98 WriteLn(' device: ' + IntToStr(FDeviceId)); 59 99 end; 60 100 61 //{$IFDEF AudioSystemDSP} 101 procedure TAudioSystemDSP.CloseDevice; 102 begin 103 if FDeviceId >= 0 then FpClose(FDeviceId); 104 end; 105 106 constructor TAudioSystemDSP.Create(AOwner: TComponent); 107 begin 108 inherited; 109 BitsPerSample := 16; 110 Channels := 2; 111 SampleRate := 44000; 112 end; 113 114 destructor TAudioSystemDSP.Destroy; 115 begin 116 inherited Destroy; 117 end; 62 118 63 119 { TPlayerMAD } 64 120 121 procedure TPlayerDSP.TimerExecute(Sender: TObject); 122 var 123 Buffer: array of Byte; 124 Size: Integer; 125 begin 126 SetLength(Buffer, 10000); 127 Size := WavFile.SourceFile.Read(PByte(Buffer)^, System.Length(Buffer)); 128 Write('Buf: ' + IntToStr(Size) + ', '); 129 fpWrite(TAudioSystemDSP(AudioSystem).FDeviceId, PByte(Buffer)^, Size); 130 FTimer.Interval := 100; 131 end; 132 65 133 procedure TPlayerDSP.Play; 66 134 begin 67 inherited Play; 68 135 WriteLn('Stop'); 136 Stop; 137 TAudioSystemDSP(AudioSystem).SampleRate := WavFile.SampleRate; 138 TAudioSystemDSP(AudioSystem).Channels := WavFile.ChannelModeID; 139 TAudioSystemDSP(AudioSystem).BitsPerSample := WavFile.BitsPerSample; 140 TAudioSystemDSP(AudioSystem).OpenDevice; 141 WriteLn('seek'); 142 WavFile.SourceFile.Seek(SizeOf(TWAVRecord), soFromBeginning); 143 while WavFile.SourceFile.Position < WavFile.SourceFile.Size do 144 TimerExecute(nil); 145 WriteLn('int'); 146 FTimer.Interval := 10; 147 FTimer.OnTimer := TimerExecute; 148 WriteLn('ena'); 149 //FTimer.Enabled := True; 150 WriteLn('true'); 69 151 end; 70 152 71 153 procedure TPlayerDSP.Pause; 72 154 begin 73 i nherited Pause;155 if FActive then FTimer.Enabled := not FTimer.Enabled; 74 156 end; 75 157 … … 77 159 begin 78 160 inherited Stop; 161 FTimer.Enabled := False; 162 TAudioSystemDSP(AudioSystem).CloseDevice; 79 163 end; 80 164 81 //{$ENDIF} 165 procedure TPlayerDSP.Open; 166 begin 167 inherited; 168 WavFile.OpenFile(FFileName); 169 end; 82 170 171 procedure TPlayerDSP.Close; 172 begin 173 inherited Close; 174 end; 175 176 constructor TPlayerDSP.Create(AOwner: TComponent); 177 begin 178 inherited; 179 WavFile := TWAVFile.Create; 180 FTimer := TTimer.Create(nil); 181 end; 182 183 destructor TPlayerDSP.Destroy; 184 begin 185 FreeAndNil(FTimer); 186 FreeAndNil(WavFile); 187 inherited Destroy; 188 end; 189 190 {$ENDIF} 83 191 84 192 end. 85 -
CoolAudio/Systems/FMOD/UAudioSystemFMOD.pas
r351 r352 1 1 unit UAudioSystemFMOD; 2 2 3 {$mode objfpc}{$H+} 3 {$I UCoolAudioConfig.inc} 4 {$mode delphi}{$H+} 4 5 5 6 interface 6 7 8 {$IFDEF AudioSystemFMOD} 7 9 uses 8 10 Classes, SysUtils, fmoddyn, fmodtypes, UAudioSystem, DateUtils; … … 39 41 end; 40 42 43 {$ENDIF} 44 45 41 46 implementation 47 48 {$IFDEF AudioSystemFMOD} 42 49 43 50 { TAudioSystemFMOD } … … 129 136 end; 130 137 138 {$ENDIF} 139 131 140 end. 132 141 -
CoolAudio/Systems/MAD/UAudioSystemMAD.pas
r351 r352 1 1 unit UAudioSystemMAD; 2 2 3 {$I UCoolAudioConfig.inc} 3 4 {$mode delphi}{$H+} 4 5 -
CoolAudio/Systems/UAudioSystem.pas
r347 r352 86 86 end; 87 87 88 const 89 WavFileExt = '.wav'; 90 Mp3FileExt = '.mp3'; 91 88 92 resourcestring 89 93 SOpenOutputFailed = 'Failed opening audio output'; … … 224 228 destructor TPlayer.Destroy; 225 229 begin 230 Stop; 226 231 Active := False; 227 232 inherited Destroy; -
CoolAudio/Systems/WinAPI/UAudioSystemWindows.pas
r351 r352 1 1 unit UAudioSystemWindows; 2 2 3 {$mode objfpc}{$H+} 3 {$I UCoolAudioConfig.inc} 4 {$mode delphi}{$H+} 4 5 5 6 interface … … 187 188 Parm: TMCI_Generic_Parms; 188 189 begin 189 FFlags := 0; 190 if FUseNotify then 191 begin 192 if FNotify then FFlags := mci_Notify; 193 FUseNotify := False; 194 end else FFlags := mci_Notify; 195 if FUseWait then 196 begin 197 if FWait then FFlags := FFlags or mci_Wait; 198 FUseWait := False; 199 end; 200 CheckError(mciSendCommand(FDeviceID, mci_Stop, FFlags, Longint(@Parm))); 201 FPlaying := False; 190 if FPlaying then begin 191 FFlags := 0; 192 if FUseNotify then 193 begin 194 if FNotify then FFlags := mci_Notify; 195 FUseNotify := False; 196 end else FFlags := mci_Notify; 197 if FUseWait then 198 begin 199 if FWait then FFlags := FFlags or mci_Wait; 200 FUseWait := False; 201 end; 202 CheckError(mciSendCommand(FDeviceID, mci_Stop, FFlags, Longint(@Parm))); 203 FPlaying := False; 204 Position := 0; 205 end; 202 206 end; 203 207 -
CoolAudio/Systems/mplayer/UAudioSystemMPlayer.pas
r351 r352 3 3 unit UAudioSystemMPlayer; 4 4 5 {$I UCoolAudioConfig.inc} 5 6 {$mode Delphi}{$H+} 6 7
Note:
See TracChangeset
for help on using the changeset viewer.