Results 1 to 2 of 2

Thread: OpenAL Wrapper from noeska.com

  1. #1

    OpenAL Wrapper from noeska.com

    wasn't sure where to post this since not many topics regarding the wrapper, anyways i implemented it into my engine and find a small memory leak, thought i'd share the small fix

    in openal.pas

    at
    Code:
    function LoadWavStream(Stream: Tstream; var format: TALenum; var data: TALvoid; var size: TALsizei; var freq: TALsizei; var loop: TALint): Boolean;
    add below line
    Code:
    name := readname[0]+readname[1]+readname[2]+readname[3];
    Code:
    freemem(readname, 4);
    anyways i also wrote an improved alutLoadWAVFile

    Code:
    procedure alutLoadWAVFile(fname: string; var format: TALenum; var data: TALvoid; var size: TALsizei; var freq: TALsizei; var loop: TALint);
    //////
    /// Colin Stewart (colin[at]overhertz.com)
    /// 22.01.2011
    //////
    var
      wavFile: File;
      fPos: Integer;
      wavHeader: TWavHeader;
      name: array[0..3] of AnsiChar;
    begin
      //assign file
      AssignFile(wavFile, fname);
      //open in readonly mode
      FileMode := fmOpenRead;
      Reset(wavFile, 1);
      //read wav header
      BlockRead(wavFile, wavHeader, SizeOf(TWavHeader));
      //set samplerate
      freq := WavHeader.SampleRate;
      //set format
      format := (AL_FORMAT_MONO8-1)+WavHeader.ChannelNumber+(WavHeader.BitsPerSample div 8);
      //AL_FORMAT_MONO8 = 4352
      format := 4349 + (WavHeader.ChannelNumber*2)+(WavHeader.BitsPerSample div 8);
      //Seek(wavFile
      Seek(wavFile, WavHeader.FormatHeaderSize-16);
    
      fPos := FilePos(wavFile);
      //run through wav file
      while not Eof(wavFile) do begin
        //read chunk name
        BlockRead(wavFile, name, 4);
        Inc(fPos, 4);
        if name = 'data' then begin
          //get size of wave data
          BlockRead(wavFile, size, 4);
          //read wave data
          GetMem(data, size);
          BlockRead(wavFile, Data^, size);
          Inc(fPos, size+4);
    
          //decode if needed/possible
          case WavHeader.FormatCode of
            WAV_IMA_ADPCM: ; //TODO
            WAV_MP3: ; //TODO
          end;
        end else begin
          //Skip unknown chunk(s)
          Inc(fPos, 4);
          Seek(wavFile, fPos);
        end;
      end;
    end;
    -Colin

  2. #2
    Thanks! I'm using this unit for a long time now. Hope Noeska can apply the fix to his downloadable version.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL