Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 54

Thread: Play a piece of a mp3 stream with mmsystem or directsound??

  1. #31

    Play a piece of a mp3 stream with mmsystem or directsound??

    make sure your calling convention is correct. It will most likely be cdecl if nothing else is specified. Looking at your code, it looks like you are using register convention on the Delphi side and that c lib will know nothing about this. It will crash.
    Jarrod Davis
    Technical Director @ Piradyne Games

  2. #32

    Play a piece of a mp3 stream with mmsystem or directsound??

    im using direct sound Smile
    Oops ops: I had similair probs with OpenAL so i thought you used OpenAL.

    Like i and jarrod said, it has probably to do with the calling convention of one or more functions you are trying to use.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #33

    Play a piece of a mp3 stream with mmsystem or directsound??

    Quote Originally Posted by Pyrogine
    make sure your calling convention is correct. It will most likely be cdecl if nothing else is specified. Looking at your code, it looks like you are using register convention on the Delphi side and that c lib will know nothing about this. It will crash.
    SHIT, im so idiot, i forget the cdecl; on the dymamic variables -.-

    now it works perfectly
    From brazil (:

    Pascal pownz!

  4. #34

    Play a piece of a mp3 stream with mmsystem or directsound??

    Can you plz post your working code now? :razz:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #35

    Play a piece of a mp3 stream with mmsystem or directsound??

    [pascal]unit mp3stream;

    interface

    uses
    SysUtils, Windows, Classes, DirectSound, MMSystem, mpg123;


    type
    TMP3 = class(TThread)
    public
    FFileName: string;
    Fhandle: Pmpg123_handle;
    Frate: Integer;
    Fchannels: Integer;
    Fencoding: Integer;
    Fbuffersize: Cardinal;

    FPlaying: Boolean;
    public
    procedure updatebuffer;
    procedure prebuffer;
    procedure Play;
    procedure Stop;
    procedure Execute; override;
    public
    function initmpg123: Boolean;
    constructor Create(const filepath: string);
    destructor Destroy; override;
    end;

    implementation

    uses
    main;

    { TMP3 }

    constructor TMP3.Create(const filepath: string);
    begin
    inherited Create(True);
    FFileName := filepath;
    Priority := tpTimeCritical;
    if FileExists(FFileName) then
    initmpg123;
    end;

    destructor TMP3.Destroy;
    begin
    mpg123_close(Fhandle);
    mpg123_exit;
    inherited;
    end;

    procedure TMP3.Execute;
    var
    critical : RTL_CRITICAL_SECTION;
    begin
    InitializeCriticalSection(critical);
    EnterCriticalSection(critical);
    repeat
    updatebuffer;
    Sleep(300);
    until Terminated;
    LeaveCriticalSection(critical);
    DeleteCriticalSection(critical);
    end;

    function TMP3.initmpg123: Boolean;
    begin
    Result := False;
    if mpg123_init <> 0 then Exit;

    Fhandle := mpg123_new('MMX', nil); // MMX is common
    if Fhandle = nil then Exit;
    mpg123_open(Fhandle, PChar(FFileName));
    mpg123_getformat(Fhandle, @Frate, @Fchannels, @Fencoding);
    mpg123_format_none(Fhandle);
    mpg123_format(Fhandle, Frate, Fchannels, Fencoding);
    end;

    procedure TMP3.Play;
    begin
    prebuffer;
    resume;
    sbuffer.Play(0, 0, DSBPLAY_LOOPING);
    end;

    procedure TMP3.Stop;
    begin
    Suspend;
    sbuffer.Stop;
    end;

    procedure TMP3.prebuffer;
    var
    buffer: PByte;
    size: Cardinal;
    d: Cardinal;
    begin
    Fbuffersize := wfm.nAvgBytesPerSec;

    sbuffer.Lock(0, Fbuffersize, @buffer, @size, nil, nil, 0);

    mpg123_read(Fhandle, buffer, size, @d);

    sbuffer.Unlock(buffer, size, nil, 0);
    end;

    procedure TMP3.updatebuffer;
    var
    buffer: PByte;
    size: Cardinal;
    d: Cardinal;
    e : Cardinal;
    section : Cardinal;
    begin
    e := WaitForMultipleObjects(2,@events,False,0);

    if e = 0 then
    section := 1
    else
    if e = 1 then
    section := 0
    else
    exit;



    sbuffer.Lock(section*Fbuffersize,Fbuffersize,@buff er,@size,nil,nil,0);

    mpg123_read(Fhandle, buffer, size, @d);

    sbuffer.Unlock(buffer,size,nil,0);
    end;

    end.
    [/pascal]
    [pascal]unit main;

    interface

    uses
    SysUtils,
    Windows,
    DirectSound,
    MMSystem,
    Classes,
    mp3stream;

    var
    DS: IDirectSound8;
    dsnotify : IDirectSoundNotify8;
    events : array [0..1] of Cardinal;
    notifs : array [0..1] of TDSBPOSITIONNOTIFY;

    sbuffer: IDirectSoundBuffer;

    wfm: TWAVEFORMATEX;
    desc: TDSBUFFERDESC;

    mp3: TMP3;

    procedure RUN;

    implementation

    procedure RUN;
    begin
    IsMultiThread := True;
    SetConsoleTitle('APP');

    mp3 := TMP3.Create('mp3.mp3');

    if DirectSoundCreate8(nil, DS, nil) <> DS_OK then Exit;

    if DS.SetCooperativeLevel(FindWindow(nil, 'APP'), DSSCL_NORMAL) <> DS_OK then Exit; ;

    FillChar(wfm, SizeOf(wfm), 0);
    wfm.cbSize := SizeOf(wfm);
    wfm.nChannels := mp3.Fchannels;
    wfm.wBitsPerSample := 16;
    wfm.nSamplesPerSec := mp3.Frate;
    wfm.nAvgBytesPerSec := wfm.nSamplesPerSec * wfm.nChannels * 2;
    wfm.nBlockAlign := 2 * wfm.nChannels;
    wfm.wFormatTag := WAVE_FORMAT_PCM;

    // set up the buffer
    desc.dwSize := SizeOf(desc);
    desc.dwFlags := 0;
    desc.lpwfxFormat := @wfm;
    desc.dwReserved := 0;
    desc.dwBufferBytes := wfm.nAvgBytesPerSec * 2;

    desc.dwFlags :=
    DSBCAPS_STATIC or
    DSBCAPS_CTRLPOSITIONNOTIFY or
    DSBCAPS_CTRLVOLUME or
    DSBCAPS_GLOBALFOCUS ;

    ds.CreateSoundBuffer(desc,sbuffer,nil);
    sbuffer.QueryInterface(IID_IDirectSoundNotify8,dsn otify);

    events[0] := CreateEvent(nil,False,False,'0.25 played');;
    events[1] := CreateEvent(nil,False,False,'0.75 played');
    notifs[0].hEventNotify := events[0];
    notifs[0].dwOffset := wfm.nAvgBytesPerSec div 2;
    notifs[1].hEventNotify := events[1];
    notifs[1].dwOffset := (wfm.nAvgBytesPerSec * 3) div 2;

    if dsnotify.SetNotificationPositions(2,@notifs) <> DS_OK then Exit;

    mp3.Play;


    sleep(1000 * 60 * 1);


    mp3.Stop;

    CloseHandle(events[0]);
    CloseHandle(events[1]);

    dsnotify := nil;
    sbuffer := nil;
    DS := nil;

    mp3.Free;
    end;

    end.
    [/pascal]
    From brazil (:

    Pascal pownz!

  6. #36

    Play a piece of a mp3 stream with mmsystem or directsound??

    for commercial projects i need use ogg... because to use mp3 i need pay royalty...

    you have some suggestion?
    Knowledge is power.

  7. #37

    Play a piece of a mp3 stream with mmsystem or directsound??

    I have a suggestion

    You should take a look at the ogg player example on noeska's site

    http://www.noeska.com/doal/tutorials.aspx

    The player itsself is really simple. It even doesn't have a Stop function, but i guess you are able to write one. It uses OpenAL instead of DirectSound but that shouldn't be a problem. I think openAL is much easier.

    This is a pascal version of an article that was posted on devmaster.net, about playing ogg with OpenAL. You might want to take a look at it.

    @ArthurPrs: Thanx alot for posting the code. Can you update the mpg123 header you posted on pastebin, so we can have a working version? Thanx again
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  8. #38

    Play a piece of a mp3 stream with mmsystem or directsound??

    to play ogg-files I use Squall, which is free to use and offers everything you need, including 3D sound.
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  9. #39

    Play a piece of a mp3 stream with mmsystem or directsound??

    http://pastebin.com/m7122488b

    here it is, the only dif is the calling convention;
    From brazil (:

    Pascal pownz!

  10. #40

    Play a piece of a mp3 stream with mmsystem or directsound??

    Here is my Ogg Sample & Music Playback Engine

    * it is based on a early version of PyroAudio
    * used DirectSound
    * full source code
    * load/play/mix ogg samples
    * play streaming ogg
    * reserve channels
    * thread updates audio in the background
    * load up to 256 samples and can mix up to 32 channels
    * Include a music player where you can play a directory full of ogg files
    * Include a audio player demo
    * add OggAudio.pas to your uses statement. The Audio object will be created/destroyed automatically.

    In this version globalfocus for sample is control by DirectSound which for most purposes works ok. Ideally you would want to manually control globalfocus yourself. I have this working for the streaming music. See how it's implemented to do the same for the samples.

    OggAudio Engine
    Jarrod Davis
    Technical Director @ Piradyne Games

Page 4 of 6 FirstFirst ... 23456 LastLast

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
  •