IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Lazarus Pascal Discussion :

waveIn : jamais d'événement de type MM_WIM_DATA ? [Lazarus]


Sujet :

Lazarus Pascal

  1. #1
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut waveIn : jamais d'événement de type MM_WIM_DATA ?
    Bonjour,

    Je suis en train d'expérimenter l'enregistrement du son sur l'entrée micro de ma carte son.

    J'ai réalisé ce code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
     
    unit umain;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
      mmsystem, messages;
     
    type
     
      { TMain }
     
      TMain = class(TForm)
          BStart: TButton;
          BStop: TButton;
          CBDevices: TComboBox;
          Memo1: TMemo;
          procedure BStartClick(Sender: TObject);
          procedure BStopClick(Sender: TObject);
          procedure CBDevicesChange(Sender: TObject);
          procedure FormCreate(Sender: TObject);
          procedure WndProc(var Message: TMessage); override;
      private
        { private declarations }
      public
        { public declarations }
      end;
     
    var
      Main: TMain;
     
      phwi : HWAVEIN;
      pwfx : WAVEFORMATEX;
      res : MMRESULT;
      pwh1, pwh2, pwh3 : WAVEHDR;
      buffer1, buffer2, buffer3 : array of Byte;
     
    implementation
     
    {$R *.lfm}
     
    { TMain }
     
    function waveInError(Nom: String; Resultat: MMRESULT): String;
    begin
        Nom := Nom + ' : ';
        case Resultat of
            MMSYSERR_ALLOCATED: Result := Nom + 'Specified resource is already allocated.';
            MMSYSERR_BADDEVICEID: Result := Nom + 'Specified device identifier is out of range.';
            MMSYSERR_INVALHANDLE: Result := Nom + 'Specified device handle is invalid.';
            MMSYSERR_NODRIVER: Result := Nom + 'No device driver is present.';
            MMSYSERR_NOMEM: Result := Nom + 'Unable to allocate or lock memory.';
            WAVERR_BADFORMAT: Result := Nom + 'Attempted to open with an unsupported waveform-audio format.';
            WAVERR_UNPREPARED: Result := Nom + 'The buffer pointed to by the pwh parameter hasn''t been prepared.';
            else Result := Nom + 'Unknow error.';
        end;
    end;
     
    procedure TMain.WndProc(var Message: TMessage);
    begin
        case Message.msg of
            MM_WIM_OPEN: Memo1.Lines.Add('MM_WIM_OPEN');
            MM_WIM_DATA: Memo1.Lines.Add('MM_WIM_DATA');
            MM_WIM_CLOSE: Memo1.Lines.Add('MM_WIM_CLOSE');
            WM_LBUTTONDOWN: Memo1.Lines.Add('WM_LBUTTONDOWN');
            WM_RBUTTONDOWN: Memo1.Lines.Add('WM_RBUTTONDOWN');
        end;
        inherited;
    end;
     
    procedure TMain.BStartClick(Sender: TObject);
    begin
        // Paramètres d'un en-tête de fichier WAV au format PCM : 19500Hz, 8 bits, mono
        with pwfx do
        begin
          wFormatTag := WAVE_FORMAT_PCM;
          nChannels := 1;
          nSamplesPerSec := 19500;
          wBitsPerSample := 8;
          nBlockAlign := (nChannels * wBitsPerSample) div 8;
          nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
          cbSize := 0;
        end;
     
        res := waveInOpen(@phwi, CBDevices.ItemIndex, @pwfx, Main.Handle, 0, CALLBACK_WINDOW);
     
        if res = MMSYSERR_NOERROR then
        begin
            Memo1.Lines.Add('waveInOpen : OK');
     
            SetLength(buffer1, 50);
            SetLength(buffer2, 50);
            SetLength(buffer3, 50);
     
            with pwh1 do
            begin
                lpData := PChar(buffer1);
                dwBufferLength := Length(buffer1);
                dwBytesRecorded := 0;
                dwUser := 0;
                dwFlags := 0;
                dwLoops := 0;
                lpNext := nil;
                reserved := 0;
            end;
     
            with pwh2 do
            begin
                lpData := PChar(buffer2);
                dwBufferLength := Length(buffer2);
                dwBytesRecorded := 0;
                dwUser := 0;
                dwFlags := 0;
                dwLoops := 0;
                lpNext := nil;
                reserved := 0;
            end;
     
            with pwh3 do
            begin
                lpData := PChar(buffer3);
                dwBufferLength := Length(buffer3);
                dwBytesRecorded := 0;
                dwUser := 0;
                dwFlags := 0;
                dwLoops := 0;
                lpNext := nil;
                reserved := 0;
            end;
     
            res := waveInPrepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
     
            if res = MMSYSERR_NOERROR then
            begin
                Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                res := waveInPrepareHeader(phwi, @pwh2, SizeOf(WAVEHDR));
                if res = MMSYSERR_NOERROR then
                begin
                    Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                    res := waveInPrepareHeader(phwi, @pwh3, SizeOf(WAVEHDR));
     
                    if res = MMSYSERR_NOERROR then
                    begin
                        Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                        res := waveInAddBuffer(phwi, @pwh1, SizeOf(WAVEHDR));
     
                        if res = MMSYSERR_NOERROR then
                        begin
                            Memo1.Lines.Add('waveInAddBuffer : OK');
     
                            res := waveInAddBuffer(phwi, @pwh2, SizeOf(WAVEHDR));
     
                            if res = MMSYSERR_NOERROR then
                            begin
                                Memo1.Lines.Add('waveInAddBuffer : OK');
     
                                res := waveInAddBuffer(phwi, @pwh3, SizeOf(WAVEHDR));
     
                                if res = MMSYSERR_NOERROR then
                                begin
                                    Memo1.Lines.Add('waveInAddBuffer : OK');
     
                                    res := waveInStart(phwi);
     
                                    if res = MMSYSERR_NOERROR then
                                    begin
                                        Memo1.Lines.Add('waveInStart : OK');
     
                                        CBDevices.Enabled := False;
                                        BStart.Enabled := False;
                                        BStop.Enabled := True;
                                    end
                                    else
                                    begin
                                        Memo1.Lines.Add(waveInError('waveInStart', res));
                                    end;
                                end
                                else
                                begin
                                    Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                                end;
                            end
                            else
                            begin
                                Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                            end;
                         end
                         else
                         begin
                             Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                         end;
                    end
                    else
                    begin
                        Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
                    end;
                end
                else
                begin
                    Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
                end;
             end
             else
             begin
                 Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
             end;
        end
        else
        begin
            Memo1.Lines.Add(waveInError('waveInOpen', res));
        end;
    end;
     
    procedure TMain.BStopClick(Sender: TObject);
    begin
        res := waveInReset(phwi);
     
        if res = MMSYSERR_NOERROR then
        begin
            Memo1.Lines.Add('waveInReset : OK');
            {res := waveInStop(phwi);
            res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
            res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
            res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
            res := waveInClose(phwi);}
        end
        else
        begin
            Memo1.Lines.Add(waveInError('waveInOpen', res));
        end;
     
        CBDevices.Enabled := True;
        BStart.Enabled := True;
        BStop.Enabled := False;
    end;
     
    procedure TMain.CBDevicesChange(Sender: TObject);
    begin
        if CBDevices.ItemIndex <> -1 then
           BStart.Enabled := True
        else
          BStart.Enabled := False;
    end;
     
    procedure TMain.FormCreate(Sender: TObject);
    var
        Nombre : Integer;
        i : Integer;
        res : MMRESULT;
        wic : WAVEINCAPS;
    begin
        BStart.Enabled := False;
        BStop.Enabled := False;
     
        Nombre := waveInGetNumDevs;
        for i:=0 to Nombre - 1 do
        begin
            res := waveInGetDevCaps(i, @wic, SizeOf(WAVEINCAPS));
     
            if res = MMSYSERR_NOERROR then
            begin
                CBDevices.Items.Add(wic.szPname);
            end
            else
            begin
                Memo1.Lines.Add(waveInError('waveInGetDevCaps', res));
            end;
        end;
    end;
     
    end.
    Mon problème, c'est que mon événement MM_WIM_DATA n'est jamais déclenché, savez-vous pourquoi ?

    Est-ce que la gestion des TMessage via WndProc vous semble correcte ?

    Ci-joint le projet complet pour tester et déboguer.

    EDIT :
    - 26/02/2013 à 12h18 -> Mise à jour du code source, plus complet.
    - 26/02/2013 à 15h06 -> Mise à jour du code source, choix du périphérique d'enregistrement

    Merci,
    ZiP
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    10 798
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 10 798
    Points : 15 212
    Points
    15 212
    Par défaut
    Salut,
    Citation Envoyé par [ZiP] Voir le message
    (...)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
          wFormatTag := WAVE_FORMAT_PCM;
          nSamplesPerSec := 19500;
    (...)
    Je ne sais pas si ça a un rapport (pas téléchargé ton exemple, pas de Laz sous la main), mais tu la sors d'où, cette valeur ?

    Parce que quand on regarde le lien de ton autre post, on peut y lire :
    nSamplesPerSec
    Sample rate, in samples per second (hertz). If wFormatTag is WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz.
    Il a à vivre sa vie comme ça et il est mûr sur ce mur se creusant la tête : peutêtre qu'il peut être sûr, etc.
    Oui, je milite pour l'orthographe et le respect du trait d'union à l'impératif.
    Après avoir posté, relisez-vous ! Et en cas d'erreur ou d'oubli, il existe un bouton « Modifier », à utiliser sans modération
    On a des lois pour protéger les remboursements aux faiseurs d’argent. On n’en a pas pour empêcher un être humain de mourir de misère.
    Mes 2 cts,
    --
    jp

  3. #3
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonsoir Jipété,

    En fait, c'est l’échantillonnage utilisé dans l'exemple de la DLL que j'utilise.

    C'est effectivement un format d'échantillonnage peu courant mais normalement fonctionnel.

    En fait, les évènements MM_WIM_* ne semblent jamais déclenchés.

    Je ne sais pas si le problème vient de l'interception de l'évènement ou alors de l'envoi de l'évènement.

    Les API ne semblent pas retourner de problème, elles me retournent toutes : MMSYSERR_NOERROR

    Merci,
    ZiP

  4. #4
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonsoir,

    Mise à jour de mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
     
    unit umain;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
      mmsystem, messages;
     
    type
     
      { TMain }
     
      TMain = class(TForm)
          BStart: TButton;
          BStop: TButton;
          CBDevices: TComboBox;
          Memo1: TMemo;
          procedure BStartClick(Sender: TObject);
          procedure BStopClick(Sender: TObject);
          procedure CBDevicesChange(Sender: TObject);
          procedure FormCreate(Sender: TObject);
      private
        { private declarations }
      protected
        procedure WndProc(var Message: TMessage); override;
      public
        { public declarations }
      end;
     
    var
      Main: TMain;
     
      phwi : HWAVEIN;
      pwfx : WAVEFORMATEX;
      res : MMRESULT;
      pwh1, pwh2, pwh3 : WAVEHDR;
      buffer1, buffer2, buffer3 : array of Byte;
     
    implementation
     
    {$R *.lfm}
     
    { TMain }
     
    function waveInError(Nom: String; Resultat: MMRESULT): String;
    begin
        Nom := Nom + ' : ';
        case Resultat of
            MMSYSERR_ALLOCATED: Result := Nom + 'Specified resource is already allocated.';
            MMSYSERR_BADDEVICEID: Result := Nom + 'Specified device identifier is out of range.';
            MMSYSERR_INVALHANDLE: Result := Nom + 'Specified device handle is invalid.';
            MMSYSERR_NODRIVER: Result := Nom + 'No device driver is present.';
            MMSYSERR_NOMEM: Result := Nom + 'Unable to allocate or lock memory.';
            WAVERR_BADFORMAT: Result := Nom + 'Attempted to open with an unsupported waveform-audio format.';
            WAVERR_UNPREPARED: Result := Nom + 'The buffer pointed to by the pwh parameter hasn''t been prepared.';
            else Result := Nom + 'Unknow error.';
        end;
    end;
     
    procedure TMain.WndProc(var Message: TMessage);
    begin
        case Message.msg of
            MM_WIM_OPEN: Memo1.Lines.Add('MM_WIM_OPEN');
            MM_WIM_DATA: Memo1.Lines.Add('MM_WIM_DATA');
            MM_WIM_CLOSE: Memo1.Lines.Add('MM_WIM_CLOSE');
            WM_LBUTTONDOWN: Memo1.Lines.Add('WM_LBUTTONDOWN');
            WM_RBUTTONDOWN: Memo1.Lines.Add('WM_RBUTTONDOWN');
        end;
        inherited WndProc(Message);
    end;
     
    procedure TMain.BStartClick(Sender: TObject);
    begin
        // Paramètres d'un en-tête de fichier WAV au format PCM : 19500Hz, 8 bits, mono
        with pwfx do
        begin
          wFormatTag := WAVE_FORMAT_PCM;
          nChannels := 1;
          nSamplesPerSec := 19500;
          wBitsPerSample := 8;
          nBlockAlign := (nChannels * wBitsPerSample) div 8;
          nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
          cbSize := 0;
        end;
     
        res := waveInOpen(@phwi, CBDevices.ItemIndex, @pwfx, Main.Handle, 0, CALLBACK_WINDOW);
     
        if res = MMSYSERR_NOERROR then
        begin
            Memo1.Lines.Add('waveInOpen : OK');
     
            SetLength(buffer1, pwfx.nAvgBytesPerSec * 5);
            SetLength(buffer2, pwfx.nAvgBytesPerSec * 5);
            SetLength(buffer3, pwfx.nAvgBytesPerSec * 5);
     
            with pwh1 do
            begin
                lpData := PChar(buffer1);
                dwBufferLength := Length(buffer1);
                dwFlags := 0;
            end;
     
            with pwh2 do
            begin
                lpData := PChar(buffer2);
                dwBufferLength := Length(buffer2);
                dwFlags := 0;
            end;
     
            with pwh3 do
            begin
                lpData := PChar(buffer3);
                dwBufferLength := Length(buffer3);
                dwFlags := 0;
            end;
     
            res := waveInPrepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
     
            if res = MMSYSERR_NOERROR then
            begin
                Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                res := waveInPrepareHeader(phwi, @pwh2, SizeOf(WAVEHDR));
                if res = MMSYSERR_NOERROR then
                begin
                    Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                    res := waveInPrepareHeader(phwi, @pwh3, SizeOf(WAVEHDR));
     
                    if res = MMSYSERR_NOERROR then
                    begin
                        Memo1.Lines.Add('waveInPrepareHeader : OK');
     
                        res := waveInAddBuffer(phwi, @pwh1, SizeOf(WAVEHDR));
     
                        if res = MMSYSERR_NOERROR then
                        begin
                            Memo1.Lines.Add('waveInAddBuffer : OK');
     
                            res := waveInAddBuffer(phwi, @pwh2, SizeOf(WAVEHDR));
     
                            if res = MMSYSERR_NOERROR then
                            begin
                                Memo1.Lines.Add('waveInAddBuffer : OK');
     
                                res := waveInAddBuffer(phwi, @pwh3, SizeOf(WAVEHDR));
     
                                if res = MMSYSERR_NOERROR then
                                begin
                                    Memo1.Lines.Add('waveInAddBuffer : OK');
     
                                    res := waveInStart(phwi);
     
                                    if res = MMSYSERR_NOERROR then
                                    begin
                                        Memo1.Lines.Add('waveInStart : OK');
     
                                        CBDevices.Enabled := False;
                                        BStart.Enabled := False;
                                        BStop.Enabled := True;
                                    end
                                    else
                                    begin
                                        Memo1.Lines.Add(waveInError('waveInStart', res));
                                    end;
                                end
                                else
                                begin
                                    Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                                end;
                            end
                            else
                            begin
                                Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                            end;
                         end
                         else
                         begin
                             Memo1.Lines.Add(waveInError('waveInAddBuffer', res));
                         end;
                    end
                    else
                    begin
                        Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
                    end;
                end
                else
                begin
                    Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
                end;
             end
             else
             begin
                 Memo1.Lines.Add(waveInError('waveInPrepareHeader', res));
             end;
        end
        else
        begin
            Memo1.Lines.Add(waveInError('waveInOpen', res));
        end;
    end;
     
    procedure TMain.BStopClick(Sender: TObject);
    begin
        res := waveInStop(phwi);
     
        if res = MMSYSERR_NOERROR then
        begin
            Memo1.Lines.Add('waveInStop : OK');
     
            res := waveInReset(phwi);
     
            if res = MMSYSERR_NOERROR then
            begin
                Memo1.Lines.Add('waveInReset : OK');
     
                res := waveInClose(phwi);
     
                if res = MMSYSERR_NOERROR then
                begin
                    Memo1.Lines.Add('waveInClose : OK');
     
                    res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
     
                    if res = MMSYSERR_NOERROR then
                    begin
                        Memo1.Lines.Add('waveInUnprepareHeader : OK');
     
                        res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
     
                        if res = MMSYSERR_NOERROR then
                        begin
                            Memo1.Lines.Add('waveInUnprepareHeader : OK');
     
                            res := waveInUnprepareHeader(phwi, @pwh1, SizeOf(WAVEHDR));
     
                            if res = MMSYSERR_NOERROR then
                            begin
                                Memo1.Lines.Add('waveInUnprepareHeader : OK');
                            end
                            else
                            begin
                                Memo1.Lines.Add(waveInError('waveInUnprepareHeader', res));
                            end;
                        end
                        else
                        begin
                            Memo1.Lines.Add(waveInError('waveInUnprepareHeader', res));
                        end;
                    end
                    else
                    begin
                        Memo1.Lines.Add(waveInError('waveInUnprepareHeader', res));
                    end;
                end
                else
                begin
                    Memo1.Lines.Add(waveInError('waveInClose', res));
                end;
            end
            else
            begin
                Memo1.Lines.Add(waveInError('waveInReset', res));
            end;
        end
        else
        begin
            Memo1.Lines.Add(waveInError('waveInStop', res));
        end;
     
        CBDevices.Enabled := True;
        BStart.Enabled := True;
        BStop.Enabled := False;
    end;
     
    procedure TMain.CBDevicesChange(Sender: TObject);
    begin
        if CBDevices.ItemIndex <> -1 then
           BStart.Enabled := True
        else
          BStart.Enabled := False;
    end;
     
    procedure TMain.FormCreate(Sender: TObject);
    var
        Nombre : Integer;
        i : Integer;
        res : MMRESULT;
        wic : WAVEINCAPS;
    begin
        BStart.Enabled := False;
        BStop.Enabled := False;
     
        Nombre := waveInGetNumDevs;
        for i:=0 to Nombre - 1 do
        begin
            res := waveInGetDevCaps(i, @wic, SizeOf(WAVEINCAPS));
     
            if res = MMSYSERR_NOERROR then
            begin
                CBDevices.Items.Add(wic.szPname);
            end
            else
            begin
                Memo1.Lines.Add(waveInError('waveInGetDevCaps', res));
            end;
        end;
    end;
     
    end.
    Amélioration du contrôle des erreurs et arrêt propre de la capture.

    A force de glaner des informations sur Internet, j'essaie d'améliorer mon code.

    Par contre, ça ne fonctionne toujours pas.

    Merci,
    ZiP
    Fichiers attachés Fichiers attachés

  5. #5
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour,

    Les messages ne passent pas par WndProc !

    Il faut créer son propre gestionnaire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    var
      Form1: TForm1;
      PrevWndProc: WNDPROC;   { remember the original WNDPROC}
     
    function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
    begin
      result := 1;
      case uMsg of
        mm_wom_open:  Form1.mm_wom_Open;
        mm_wom_done:  Form1.mm_wom_Done(lParam);
        mm_wom_close: Form1.mm_wom_Close;
      end; {case}
       result := CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam);
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      PrevWndProc := Windows.WNDPROC(SetWindowLong(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)));
    end;
     
    procedure TForm1.mm_wom_close;
    begin
     
    end;
    Voilà !

    ZiP

  6. #6
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 448
    Points
    28 448
    Par défaut
    surprenant...

    sous Delphi il suffit de déclarer une méthode de message, ça ne fonctionne pas sous Lazarus ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    type
      TForm1 = class(TForm)
      ...
      procedure MMWinData(var Msg: TMessage); message MM_WIM_DATA;
      ...
      end;
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  7. #7
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour Paul,

    Non, je n'intercepte jamais ces évènements avec la méthode du WndProc.

    Je viens de tester, avec la votre non plus.

    Cordialement,
    ZiP

  8. #8
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 448
    Points
    28 448
    Par défaut
    j'ai reproduit ton code sous Delphi 6

    Memo1
    waveInOpen : OK
    waveInPrepareHeader : OK
    waveInPrepareHeader : OK
    waveInPrepareHeader : OK
    waveInAddBuffer : OK
    waveInAddBuffer : OK
    waveInAddBuffer : OK
    waveInStart : OK
    MM_WIN_OPEN
    MM_WIN_DATA
    MM_WIN_DATA
    waveInStop : OK
    waveInReset : OK
    waveInClose : OK
    waveInUnprepareHeader : Specified device handle is invalid.
    MM_WIN_DATA
    MM_WIN_CLOSE
    
    Delphi.zip
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  9. #9
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour Paul,

    C'est en effet plus simple pour la gestion des messages en Delphi.

    J'ai également le problème avec Lazarus, je pense qu'il faut que je place le waveInUnprepareHeader avant d'arrêter l'enregistrement.

    Je continue à travailler dessus ce week-end.

    Cordialement,
    ZiP

  10. #10
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    J'apporte une précision, je viens de tester ton code avec Lazarus, il fonctionne, j'intercepte bien les évènements !

    Merci pour ce bout de code qui est beaucoup propre que le mien

    ZiP

  11. #11
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour Paul,

    Je pense avoir fait une bêtise en vérifiant votre code l'autre jour.

    L'utilisation de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    procedure MMWinData(var Msg: TMessage); message MM_WIM_DATA;
    ne fonctionne pas avec Lazarus

    Cordialement,
    ZiP

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Observateur] Gérer plusieurs événements/ plusieurs types d'observateurs
    Par nanou2002 dans le forum Design Patterns
    Réponses: 1
    Dernier message: 27/10/2009, 10h50
  2. Gestion d'un évènement type "onoverflow"
    Par proner dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 14/06/2007, 10h29
  3. Réponses: 3
    Dernier message: 15/02/2007, 12h04
  4. Comment connaître le type d'évènement déclencheur du trigger
    Par vincent.delhommois dans le forum PL/SQL
    Réponses: 4
    Dernier message: 18/09/2006, 15h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo