Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Mai 18, 2024 23:15

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 6 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Ogg and OpenAL
BeitragVerfasst: Sa Nov 27, 2004 10:36 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Hello,

I've a procedure that loads ogg audio files with the ogg vorbis audio library. It works with some audio files, but it doesn't work always. I think there is something wrong with setLength(buffer,...) functions but I don't know exactely what. I don't want to stream the oggs, I want to load them completely in one time. Is there somebody who knows what's wrong?
Code:
  1.  
  2. type
  3.   TALSource = record
  4.     source: Taluint;
  5.     position: Array[0..2] of TALFloat;
  6.     buffer : TALuint;
  7.   end;
  8.  
  9.  
  10. procedure LoadOGG(fileName: String;var buffer: TByteArray;var format: TALEnum;var freq: TALSizei);
  11. var
  12.   Res : Integer;
  13.   oggFile: TFileStream;
  14.   OGGStream: OGGVorbis_File;
  15.   VorbisInfo    : Vorbis_Info;
  16.   Source        : TALUInt;
  17.   bbyte: byte;
  18.   bitStream: integer = 0;
  19.   bytes: integer;
  20.   counter: integer;
  21. begin
  22.   // Load the OGG-File into a Filestream
  23.     setLength(buffer,32768);
  24.   OggFile := TFileStream.Create(FileName, fmOpenRead);
  25.   Res := ov_open_callbacks(OggFile, OggStream, nil, 0, ops_callbacks);
  26.   if Res <> 0 then
  27.   begin
  28.     writeLn('Failed');
  29.     exit;
  30.   end;
  31.   //Get some infos out of the OGG-file
  32.   VorbisInfo    := ov_info(OggStream,-1)^;
  33.   if VorbisInfo.channels = 1 then
  34.     Format := AL_FORMAT_MONO16
  35.   else
  36.     Format := AL_FORMAT_STEREO16;
  37.   counter := 0;
  38.   freq := VorbisInfo.rate;
  39.   repeat
  40.     //Keep reading until all is read
  41.     //Read up to a buffer's worth of decoded sound data
  42.     bytes := ov_read(OGGStream, buffer[counter], 32768, 0, 2, 1, @bitStream);
  43.   if bytes > 0 then
  44.   begin
  45.     inc(counter,bytes);
  46.     setLength(buffer,length(buffer)+32768);
  47.   end;
  48.  
  49.   // Append to end of buffer
  50.   until(bytes <= 0);
  51.  
  52.   //Clean up!
  53.   ov_clear(OGGStream);
  54. end;
  55.  
  56.  
  57. //************************************************************************************************
  58. //Load audio
  59. //************************************************************************************************
  60. procedure loadAudio();
  61. var
  62.   format: TALenum;                          // The sound data format
  63.   freq: TALsizei;                           // The frequency of the sound data
  64.   bufferData: TByteArray;                // The sound buffer data from file
  65.   state: TALint;                            // The state of the sound source
  66. begin
  67.   loadOgg(localDir + 'audio/rain.ogg',bufferData, format, freq);
  68.   alGenBuffers(1, @alSource[0].buffer);
  69.   alBufferData(alSource[0].buffer, format, @bufferData[0], length(bufferData), freq);
  70.  
  71.   alGenSources(1,@alSource[0].source);
  72.  
  73.   alSourcef(alSource[0].source, AL_PITCH, 1.0);
  74.   alSourcef(alSource[0].source, AL_GAIN, 1.0);
  75.   alSourcei(alSource[0].source, AL_BUFFER, alSource[0].buffer);
  76.   alSourcei(alSource[0].source, AL_LOOPING, AL_TRUE);
  77.   alSourcei(alSource[0].source, AL_BUFFER, alSource[0].buffer);
  78.   alSourcef(alSource[0].source, AL_POSITION, alSource[0].position[0]);
  79.   alSourcePlay(alSource[0].source);
  80.  
  81. end;
  82.  


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Nov 27, 2004 11:55 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
did you take a look at: http://www.noeska.com/doal/lesson9.aspx. it is much easier that way.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Nov 27, 2004 12:38 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
noeska hat geschrieben:
did you take a look at: http://www.noeska.com/doal/lesson9.aspx. it is much easier that way.


I know. But this extension is only available in the OpenAL beta version. I prefer a stable version that is available on more systems.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Nov 28, 2004 14:56 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
I've already found a solution. Thanks anyway.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Nov 28, 2004 15:27 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Care about sharing it with the rest of us? Please post your solution below...

PS rumour has it that March 2005 ogg will be in the release version of openal

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Nov 28, 2004 15:48 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Here it is:
Code:
  1.  
  2. procedure AppendBytes(var ADest: TByteArray; const AAppend: Array of Byte; ALength: integer);
  3. var
  4.   iStart:     Integer;
  5.  
  6. begin
  7.   if High(AAppend) < 0 then
  8.     exit;
  9.  
  10.   // Make room for the extra bytes
  11.   iStart  := Length(ADest);
  12.   SetLength(ADest, iStart + ALength);
  13.  
  14.   // Copy the data
  15.   Move(AAppend[0], ADest[iStart], ALength);
  16. end;
  17.  
  18.  
  19. procedure LoadOGG(fileName: String;var buffer: TByteArray;var format: TALEnum;var freq: TALSizei);
  20. var
  21.   Res : Integer;
  22.   oggFile: TFileStream;
  23.   OGGStream: OGGVorbis_File;
  24.   VorbisInfo    : Vorbis_Info;
  25.   Source        : TALUInt;
  26.   bbyte: byte;
  27.   bitStream: integer = 0;
  28.   bytes: integer;
  29.   counter: integer;
  30.   byteArray: Array[0..32768] of byte;
  31. begin
  32.   // Load the OGG-File into a Filestream
  33.   OggFile := TFileStream.Create(FileName, fmOpenRead);
  34.   Res := ov_open_callbacks(OggFile, OggStream, nil, 0, ops_callbacks);
  35.   if Res <> 0 then
  36.   begin
  37.     writeLn('Failed');
  38.     exit;
  39.   end;
  40.   //Get some infos out of the OGG-file
  41.   VorbisInfo    := ov_info(OggStream,-1)^;
  42.   if VorbisInfo.channels = 1 then
  43.     Format := AL_FORMAT_MONO16
  44.   else
  45.     Format := AL_FORMAT_STEREO16;
  46.   counter := 0;
  47.   freq := VorbisInfo.rate;
  48.   repeat
  49.     //Keep reading until all is read
  50.     //Read up to a buffer's worth of decoded sound data
  51.     bytes := ov_read(OGGStream, byteArray[0], 32768, 0, 2, 1, @bitStream);
  52.   if bytes > 0 then
  53.   begin
  54.     inc(counter,bytes);
  55.     appendBytes(buffer,byteArray,bytes);
  56.   end;
  57.  
  58.   // Append to end of buffer
  59.   until(bytes <= 0);
  60.  
  61.   //Clean up!
  62.   ov_clear(OGGStream);
  63. end;
  64.  


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 6 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.011s | 14 Queries | GZIP : On ]