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

API, COM et SDKs Delphi Discussion :

[Android] Audiotrack : pas de son ! Encapsuler le tout dans un Thread (ouch !)


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut [Android] Audiotrack : pas de son ! Encapsuler le tout dans un Thread (ouch !)
    Bonjour bonjour,
    Ça faisait un bail que je n'étais pas passé sur les forums donc bonjour aux anciens qui passeront par là.

    Grosso modo, je réalise un "magnetophone à cassettes" sous Android.
    Pour être plus clair le programme
    - charge des fichiers .tap, qui sont des cassettes digitalisées utilisées par les émulateurs d'Oric Atmos.
    - converti ces fichiers tap au format PCM (wav) en plaçant les données dans un ou plusieurs TMemoryStream successifs (correspondant à chacun des "fichiers" présents dans le fichier .tap).
    - Charge les données PCM dans un buffer d'un Audiotrack
    - Lit le PCM (avec implémentation de play/pause/stop et notification de progression) en MODE_STATIC (Je ne pence pas que le MODE_STREAM soit approprié)
    - la prise casque étant reliée à un vrai Oric, qui se sert du téléphone comme magnétophone, c'est cool.

    Le souci : Pas de son ! et interface qui ne répond plus (j'ai l'impression...).
    Pas d'erreur à l'execution, c'est déjà ça )

    J'ai le sentiment qu'il va falloir que j'encapsule tout le bazar dans un TThread, et sincèrement j'avoues ma limite à pouvoir le faire

    1) Où ai-je loupé le coche dans mon code.
    2) Qui peut m'aider ?
    3) J'insiste un peu pour l'aide parce que les projets delphi qui implemente JAudioTrack, j'en ai pas trouvé des masses sur Internet, en MODE_STATIC , je n'en ai trouvé aucun.
    4) Mon projet et ses sources sont sur Github pour qui aurait besoin de s'en inspirer : https://github.com/DJChloe/Android-TapPlayer
    5) surtout qu'en plus j'y propose quelques bons exemples utiles pour beaucoup.
    - Une implementation d'un OpenDialog pour Android
    - L'utilisation de Frames dans un TFramedVertScrollBox (c'est beaucoup plus flexible qu'un TListviewItem ou qu'un TListboxItem dans certains cas).
    6) TMediaplayer n'aime pas les fichiers wav, Le MediaPlayer natif non plus, le format mp3 est proscrit (qualité du son dégradée)
    7) J'utilise Delphi Community

    Bref, c'est tout bénef pour tout le monde.

    Sur le Github :
    - Les sources du projet.
    - des fichiers tap, parce que sinon on ne peut pas tester le programme.

    Et des screenshots.

    Merci du coup de main !
    Images attachées Images attachées    
    Bidouilleuse Delphi

  2. #2
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Héhé une revenante ,

    Il me semblait que sur Android les seuls formats supportés étaient 3GP et MP3. Et la seule manière de lire un son se faisait par le biais du TMediaPlayer :

    http://docwiki.embarcadero.com/RADSt...ans_FireMonkey

  3. #3
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Citation Envoyé par Thierry Laborde Voir le message
    Héhé une revenante ,
    Héhé, Salut Thierry

    Il me semblait que sur Android les seuls formats supportés étaient 3GP et MP3. Et la seule manière de lire un son se faisait par le biais du TMediaPlayer :

    http://docwiki.embarcadero.com/RADSt...ans_FireMonkey
    Coucou Thierry,

    Non, non, on peut passer par du Natif, exemples :
    musicplayer : https://sourceforge.net/p/radstudiod...a/MusicPlayer/
    soundpool : https://github.com/EmbarcaderoPublic...dioManager.pas
    Audiotrack en MODE_STREAM :
    - https://forums.embarcadero.com/threa...hreadID=254560
    - http://bbs.bccn.net/m.thread.php?tid=454952

    Le double avantage d'Audiotrack :
    - Il ne reconnais que l'encodage PCM (fichier wav brut de brut sans les headers)
    - On peu lui fournir des données stockées en mémoire en l'occurence un TJavaArray<Byte>


    Code source de mon unité Audio :
    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
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    unit UnitAudio;
     
    interface
     
    uses
    System.SysUtils,
    System.Classes,
    System.SyncObjs,
    System.Generics.Collections,
    FMX.Dialogs,
    Androidapi.Helpers,
    AndroidApi.JNI, Androidapi.JNI.Media,
    Androidapi.JNI.GraphicsContentViewText,
    Androidapi.JNI.Net,
    Androidapi.JNIBridge,
    Androidapi.JNI.JavaTypes;
     
    type
    {Thread Audio }
    TPlayState = (psStopped, psPlaying, psPaused, psInterrupted,psNil);
    TState = (sUnitialized, sInitialized,sNoStaticData,sNil);
     
    TPlayStateChangedEvent = procedure (APlayState: TPlayState) of object;
    TStateChangedEvent = procedure (AState: TState) of object;
    TTimeChangedEvent = procedure (ATime: single) of object;
    TDurationChangedEvent = procedure (ADuration: single) of object;
    TCompleteEvent=procedure of object;
     
    TAudioCap=record
        SampleRate:integer;
        BufferSize:integer;
    end;
    TPCM_Player=class;
     
    TPlaybackPositionUpdateListener = class(TJavaLocal, JAudioTrack_OnPlaybackPositionUpdateListener)//class(TJavaGenericImport<JAudioTrack_OnPlaybackPositionUpdateListenerClass, JAudioTrack_OnPlaybackPositionUpdateListener>) //
      private
        //Objet pour lequel il faut transmettre  la notification
        FOwner : TPCM_Player;
      public
        constructor Create(AOwner : TPCM_Player);
        //Note : la convention d'appel cdecl;
        //les implémentation doivent utiliser cette convention autrement
        //on aura erreurs de compilation.
        procedure OnMarkerReached(track: JAudioTrack); cdecl;
        procedure OnPeriodicNotification(track: JAudioTrack); cdecl;
    end;
     
    TPCM_Player=class
      private
         FSampleRate: Integer;
         FPlayState:TPlayState;
         FState:TState;
         FTime:single;
         FDuration:single;
         FComplete:boolean;
         AudioTrack: JAudioTrack;
         AudioStream: TJavaArray<Byte>;
         AudioDataSize: Integer;
         AudioPausePosition : Integer;
         FOnPlayStateChange:TPlayStateChangedEvent;
         FOnStateChange:TStateChangedEvent;
         FOnTimeChange:TTimeChangedEvent;
         FOnDurationChange:TDurationChangedEvent;
         FOnComplete:TCompleteEvent;
         PlaybackPositionUpdateListener:TPlaybackPositionUpdateListener;
         function GetPlayState:TPlayState;
         function GetState:TState;
         procedure SetPlayState(const APlayState: TPlayState);
         procedure SetState(const AState: TState);
         procedure SetTime(const ATime: Single);
         procedure SetDuration(const ADuration: Single);
         function GetTime: Single;
         function GetDuration: Single;
      protected
        procedure Release;
        procedure DoMarkerReached;
        procedure DoPeriodicNotification;
        procedure Updates;
      public
        constructor Create(SampleRate: integer);
        destructor Destroy; override;
        procedure LoadStream(AStream:TMemoryStream);
        procedure Play;
        procedure Pause;
        procedure PlayPause;
        procedure Stop;
        property PlayState:TPlayState read FPlayState;
        property State:TState read FState;
        property Time: Single read FTime;
        property Duration: Single read FDuration;
        property Complete:boolean read FComplete;
        property OnPlayStateChange:TPlayStateChangedEvent read FOnPlayStateChange write FOnPlayStateChange;
        property OnStateChange:TStateChangedEvent read FOnStateChange write FOnStateChange;
        property OnTimeChange:TTimeChangedEvent read FOnTimeChange write FOnTimeChange;
        property OnDurationChange:TDurationChangedEvent read FOnDurationChange write FOnDurationChange;
        property OnComplete:TCompleteEvent read FOnComplete write FOnComplete;
    end;
     
    function getMinSupportedSampleRate(const AnArrayOfSampleRatesToTest: array of Integer):TAudioCap;
     
    const
      TJAudioTrackPLAYSTATE_STOPPED = 1;
      TJAudioTrackPLAYSTATE_PAUSED = 2;
      TJAudioTrackPLAYSTATE_PLAYING = 3;
      TJAudioTrackMODE_STATIC = 0;
      TJAudioTrackMODE_STREAM = 1;
      TJAudioTrackSTATE_UNINITIALIZED = 0;
      TJAudioTrackSTATE_INITIALIZED = 1;
      TJAudioTrackSTATE_NO_STATIC_DATA = 2;
      TJAudioTrackSUCCESS = 0;
      TJAudioTrackERROR = -1;
      TJAudioTrackERROR_BAD_VALUE = -2;
      TJAudioTrackERROR_INVALID_OPERATION = -3;
      TJAudioFormatENCODING_INVALID = 0;
      TJAudioFormatENCODING_DEFAULT = 1;
      TJAudioFormatENCODING_PCM_16BIT = 2;
      TJAudioFormatENCODING_PCM_8BIT = 3;
      TJAudioFormatCHANNEL_CONFIGURATION_INVALID = 0;
      TJAudioFormatCHANNEL_CONFIGURATION_DEFAULT = 1;
      TJAudioFormatCHANNEL_CONFIGURATION_MONO = 2;
      TJAudioFormatCHANNEL_CONFIGURATION_STEREO = 3;
      TJAudioFormatCHANNEL_INVALID = 0;
      TJAudioFormatCHANNEL_OUT_DEFAULT = 1;
      TJAudioFormatCHANNEL_OUT_FRONT_LEFT = 4;
      TJAudioFormatCHANNEL_OUT_FRONT_RIGHT = 8;
      TJAudioFormatCHANNEL_OUT_FRONT_CENTER = 16;
      TJAudioFormatCHANNEL_OUT_LOW_FREQUENCY = 32;
      TJAudioFormatCHANNEL_OUT_BACK_LEFT = 64;
      TJAudioFormatCHANNEL_OUT_BACK_RIGHT = 128;
      TJAudioFormatCHANNEL_OUT_FRONT_LEFT_OF_CENTER = 256;
      TJAudioFormatCHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 512;
      TJAudioFormatCHANNEL_OUT_BACK_CENTER = 1024;
      TJAudioFormatCHANNEL_OUT_MONO = 4;
      TJAudioFormatCHANNEL_OUT_STEREO = 12;
      TJAudioFormatCHANNEL_OUT_QUAD = 204;
      TJAudioFormatCHANNEL_OUT_SURROUND = 1052;
      TJAudioFormatCHANNEL_OUT_5POINT1 = 252;
      TJAudioFormatCHANNEL_OUT_7POINT1 = 1020;
      TJAudioFormatCHANNEL_IN_DEFAULT = 1;
      TJAudioFormatCHANNEL_IN_LEFT = 4;
      TJAudioFormatCHANNEL_IN_RIGHT = 8;
      TJAudioFormatCHANNEL_IN_FRONT = 16;
      TJAudioFormatCHANNEL_IN_BACK = 32;
      TJAudioFormatCHANNEL_IN_LEFT_PROCESSED = 64;
      TJAudioFormatCHANNEL_IN_RIGHT_PROCESSED = 128;
      TJAudioFormatCHANNEL_IN_FRONT_PROCESSED = 256;
      TJAudioFormatCHANNEL_IN_BACK_PROCESSED = 512;
      TJAudioFormatCHANNEL_IN_PRESSURE = 1024;
      TJAudioFormatCHANNEL_IN_X_AXIS = 2048;
      TJAudioFormatCHANNEL_IN_Y_AXIS = 4096;
      TJAudioFormatCHANNEL_IN_Z_AXIS = 8192;
      TJAudioFormatCHANNEL_IN_VOICE_UPLINK = 16384;
      TJAudioFormatCHANNEL_IN_VOICE_DNLINK = 32768;
      TJAudioFormatCHANNEL_IN_MONO = 16;
      TJAudioFormatCHANNEL_IN_STEREO = 12;
    implementation
     
    function getMinSupportedSampleRate(const AnArrayOfSampleRatesToTest: array of Integer):TAudioCap;
    var i:integer;
        bufsize:integer;
    begin
      result.SampleRate:=-1;
      result.BufferSize:=-1;
      i:=Low(AnArrayOfSampleRatesToTest);
      while ((result.SampleRate<0) and (i<=High(AnArrayOfSampleRatesToTest))) do
      begin
          bufsize := TJAudioTrack.JavaClass.getMinBufferSize(AnArrayOfSampleRatesToTest[i],
                TJAudioFormat.JavaClass.CHANNEL_OUT_MONO,
                TJAudioFormat.JavaClass.ENCODING_PCM_8BIT);
        if ((bufsize <> TJAudioTrack.JavaClass.ERROR)
           and (bufsize <> TJAudioTrack.JavaClass.ERROR_BAD_VALUE)
           and (bufsize > 0))
        then begin
               result.SampleRate:= AnArrayOfSampleRatesToTest[i];
               result.BufferSize:=bufsize;
        end;
        inc(i);
      end;
    end;
     
    constructor TPCM_Player.Create(SampleRate: integer);
    var
      TelephonyManagerObj: JObject;
      LPermissions: TJavaObjectArray<JString>;
    begin
      inherited Create;
      FSampleRate:=SampleRate;
      FPlayState:=psNil;
      FState:=sNil;
      FTime:=0;
      FDuration:=0;
      AudioDataSize:=0;
      FComplete:=false;
      updates;
    end;
     
    destructor TPCM_Player.Destroy;
    begin
      inherited;
    end;
     
    procedure TPCM_Player.LoadStream(AStream:TMemoryStream);
    begin
      if Assigned(AudioTrack) then
      begin
        if AudioTrack.getPlayState<>TJAudioTrack.JavaClass.PLAYSTATE_STOPPED then exit;
        AudioTrack.release;
      end;
      FComplete:=false;
      //AudioDataSize := TJAudioTrack.JavaClass.getMinBufferSize(FSampleRate,
      //                   TJAudioFormat.JavaClass.CHANNEL_OUT_MONO,
      //                   TJAudioFormat.JavaClass.ENCODING_PCM_16BIT);
      AudioDataSize:=AStream.Size;
      AudioStream := TJavaArray<Byte>.Create(AudioDataSize);
      AStream.Position := 0;
      AStream.Read(AudioStream.Data^, AudioDataSize);
      if (not Assigned(AudioStream)) then exit;
      AudioTrack := TJAudioTrack.JavaClass.init(TJAudioManager.JavaClass.STREAM_MUSIC,
                  FSampleRate, TJAudioFormat.JavaClass.CHANNEL_OUT_MONO,
                  TJAudioFormat.JavaClass.ENCODING_PCM_8BIT, AudioDataSize,
                  TJAudioTrack.JavaClass.MODE_STATIC);
      if ((not Assigned(AudioTrack)) or (AudioDataSize=0)) then exit;
      try
        //AudioTrack.setVolume(1);
        AudioTrack.setPlaybackPositionUpdateListener(PlaybackPositionUpdateListener);
        updates;
      except
       // TODO: handle exception
       //showmessage(???);
      end;
    end;
     
    procedure TPCM_Player.Play;
    begin
      if ((not Assigned(AudioTrack)) or (AudioDataSize=0)) then exit;
      try
        if (AudioTrack.getPlayState=TJAudioTrackPLAYSTATE_PLAYING)
        then Exit;
        if AudioTrack.getPlayState=TJAudioTrackPLAYSTATE_STOPPED
        then begin
                AudioPausePosition:=0;
                AudioTrack.reloadStaticData();
                AudioTrack.write(AudioStream, 0, AudioDataSize);
                AudioTrack.setNotificationMarkerPosition(AudioDataSize);
                AudioTrack.setPositionNotificationPeriod(FSampleRate div 2); //notification toutes les 500ms
        end;
        AudioTrack.setPlaybackHeadPosition(AudioPausePosition);
        AudioTrack.play;
        updates;
      except
       // TODO: handle exception
       //showmessage(???);
      end;
    end;
     
    procedure TPCM_Player.Pause;
    begin
      if (not Assigned(AudioTrack)) then exit;
      try
        if (AudioTrack.getPlayState=TJAudioTrackPLAYSTATE_PAUSED)
        then Exit;
        if AudioTrack.getPlayState=TJAudioTrackPLAYSTATE_PLAYING
        then begin
          AudioTrack.setPlaybackHeadPosition(AudioPausePosition);
          AudioTrack.play;
          updates;
        end;
      except
       // TODO: handle exception
       //showmessage(???);
      end;
    end;
     
    procedure TPCM_Player.PlayPause;
    begin
      if ((not Assigned(AudioTrack)) or (AudioDataSize=0)) then exit;
      try
        case AudioTrack.getPlayState of
          TJAudioTrackPLAYSTATE_PLAYING:
          begin
            AudioPausePosition:=AudioTrack.getPlaybackHeadPosition;
            AudioTrack.pause;
          end;
          TJAudioTrackPLAYSTATE_PAUSED:
          begin
            AudioTrack.setPlaybackHeadPosition(AudioPausePosition);
            AudioTrack.play;
          end;
          TJAudioTrackPLAYSTATE_STOPPED:
          begin
            AudioPausePosition:=0;
            AudioTrack.reloadStaticData();
            AudioTrack.write(AudioStream, 0, AudioDataSize);
            AudioTrack.setNotificationMarkerPosition(AudioDataSize);
            AudioTrack.setPositionNotificationPeriod(FSampleRate div 2); //notification toutes les 500ms
            AudioTrack.play;
          end;
        end;
        updates;
      except
         // TODO: handle exception
         //showmessage(???);
      end;
      updates;
    end;
     
    procedure TPCM_Player.Stop;
    begin
      if not Assigned(AudioTrack) then exit;
      AudioTrack.pause;
      AudioTrack.stop;
      updates;
    end;
     
    function TPCM_Player.GetPlayState:TPlayState;
    begin
      Result:=TPlayState.psNil;
      if Assigned(AudioTrack) then
      case AudioTrack.getPlayState of
        TJAudioTrackPLAYSTATE_STOPPED:Result:=TPlayState.psStopped;
        TJAudioTrackPLAYSTATE_PAUSED:Result:=TPlayState.psPaused;
        TJAudioTrackPLAYSTATE_PLAYING:Result:=TPlayState.psPlaying;
      end;
    end;
     
    function TPCM_Player.GetState:TState;
    begin
      Result:=TState.sNil;
      if Assigned(AudioTrack) then
      case AudioTrack.getState of
        TJAudioTrackSTATE_UNINITIALIZED:Result:=TState.sUnitialized;
        TJAudioTrackSTATE_INITIALIZED:Result:=TState.sInitialized;
        TJAudioTrackSTATE_NO_STATIC_DATA:Result:=TState.sNoStaticData;
      end;
    end;
     
    procedure TPCM_Player.SetPlayState(const APlayState: TPlayState);
    begin
      if FPlayState=APlayState then exit;
      FPlayState:=APlayState;
      if Assigned(FOnPlayStateChange) then
         FOnPlayStateChange(APlayState);
    end;
     
    procedure TPCM_Player.SetState(const AState: TState);
    begin
      if FState=AState then exit;
      FState:=AState;
      if Assigned(FOnStateChange) then
         FOnStateChange(AState);
    end;
     
    procedure TPCM_Player.SetTime(const ATime: Single);
    begin
      if FTime=ATime then exit;
      FTime:=ATime;
      if Assigned(FOnTimeChange) then
         FOnTimeChange(ATime);
    end;
     
    procedure TPCM_Player.SetDuration(const ADuration: Single);
    begin
      if FDuration=ADuration then exit;
      FDuration:=ADuration;
      if Assigned(FOnDurationChange) then
         FOnDurationChange(ADuration);
    end;
     
    procedure TPCM_Player.release;
    begin
      if Assigned(AudioTrack) then
      begin
        AudioTrack.stop;
        AudioTrack.release;
      end;
    end;
     
    function TPCM_Player.GetTime: Single;
    begin
      if Assigned(AudioTrack)
      then result:=1000*AudioTrack.getPlaybackHeadPosition/FSampleRate
      else result:=0;
    end;
     
    function TPCM_Player.GetDuration: Single;
    begin
      if Assigned(AudioTrack)
      then result:=1000*AudioDataSize/FSampleRate
      else result:=0;
    end;
     
    procedure TPCM_Player.Updates;
    begin
      SetState(GetState);
      SetPlayState(GetPlayState);
      SetTime(GetTime);
      SetDuration(GetDuration);
    end;
     
    procedure TPCM_Player.DoMarkerReached;
    begin
      FComplete:=true;
      if Assigned(FOnComplete) then FOnComplete;
    end;
     
    procedure TPCM_Player.DoPeriodicNotification;
    begin
      updates;
    end;
     
    constructor TPlaybackPositionUpdateListener.Create(AOwner : TPCM_Player);
    begin
      FOwner := AOwner;
    end;
     
    procedure TPlaybackPositionUpdateListener.OnMarkerReached(track: JAudioTrack);
    begin
      FOwner.DoMarkerReached;
    end;
     
    procedure TPlaybackPositionUpdateListener.OnPeriodicNotification(track: JAudioTrack);
    begin
      FOwner.DoPeriodicNotification;
    end;
     
    end.
    Le taux d'echantillonnage supporté par le téléphone pour encoder en PCM est déterminé à la création de la fiche principale :
    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
    procedure TMainForm.FormCreate(Sender: TObject);
    var
    ac1:TAudioCap;
    const
       validSampleRates:array[0..5] of integer=(4800, 8000, 11025, 16000, 44100, 48000);
    begin
    ...
      OricTape:=TOricTape.Create;
      OricTape.OwnsObjects:=true;
     
      TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService));
      if Assigned(PhoneDialerService) then
        PhoneDialerService.OnCallStateChanged := MyOnCallStateChanged;
     
      ac1:=getMinSupportedSampleRate(validSampleRates);
      Speed:=ac1.SampleRate;
     
      FPCMPlayer:=TPCM_Player.Create(speed);
      FPCMPlayer.OnPlayStateChange:=PlayStateChanged;
      FPCMPlayer.OnTimeChange:=DoUpdateUI;
    end;
    Bidouilleuse Delphi

  4. #4
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Je n'avance pas vraiment, mis à par la correction de petits bugs, par ci par là.

    Après, la pénibilité du débogage y est pour beaucoup : c'est lent, pas très stable et assez limité en fait.
    Surtout que l'EDI de Delphi est d'une lourdeur...
    J'ai beau avoir 8Go de RAM, mon celeron N2840 il rame comme un galerien !
    Bidouilleuse Delphi

  5. #5
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 419
    Points : 5 818
    Points
    5 818
    Par défaut
    salut

    je ne vois pas ou tu joue ton son dans tes source
    si tu reprend les source de delphiArcaneGame
    il existe deux méthodes fort intéressantes


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    procedure TAudioManager.PlaySound(AIndex: integer);
    ...
    end;
     
     
    procedure TAudioManager.PlaySound(AName: String);
    ...
    end;
    sinon de façon dynamique si j'ai bien compris le write interviens après le play et non avant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    procedure PlaySound();
         at1.play;
         at1.write(soundData,0,playBufferSize);
    end;
    Nous souhaitons la vérité et nous trouvons qu'incertitude. [...]
    Nous sommes incapables de ne pas souhaiter la vérité et le bonheur, et sommes incapables ni de certitude ni de bonheur.
    Blaise Pascal
    PS : n'oubliez pas le tag

  6. #6
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Coucou Anapurna

    Citation Envoyé par anapurna Voir le message
    salut
    je ne vois pas ou tu joue ton son dans tes source
    En fait, ça se passe dans UnitAudio.pas :
    1) J'initialise audiotrack et je charge mes données dans procedure TPCM_Player.LoadStream(AStream:TMemoryStream) en deux temps :
    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
     
    [..]
      AudioDataSize:=AStream.Size;
      AudioStream := TJavaArray<Byte>.Create(AudioDataSize);
      AStream.Position := 0;
      AStream.Read(AudioStream.Data^, AudioDataSize);  //<-- Chargement du TMemoryStream dans AudioStream  (AudioStream: TJavaArray<Byte>; )
    [..]
    try
        //AudioTrack.setVolume(1);
        AudioTrack.setPlaybackPositionUpdateListener(PlaybackPositionUpdateListener);
        AudioTrack.write(AudioStream, 0, AudioDataSize);  //<-- Chargement de AudioStream  dans le buffer de AudioTrack;
        updates;
      except
       // TODO: handle exception
       //showmessage(???);
      end;
    [..]

    Puis, la lecture s'effectue dans procedure TPCM_Player.Play; :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        [..]
        AudioTrack.setPlaybackHeadPosition(AudioPausePosition);
        AudioTrack.play; // <-- Ici !
    Citation Envoyé par anapurna Voir le message
    si tu reprend les source de delphiArcaneGame
    il existe deux méthodes fort intéressantes


    [CODE]
    procedure TAudioManager.PlaySound(AIndex: integer);
    ...
    end;
    Mais oui mais non, je me suis cassée les dents dessus. Les Arcade Games utilisent l'API Android SoundPool, j'ai déjà essayé de m'en inspirer et j'ai rencontré un souci majeur avec SoundPool :
    - Ne fonctionne que pour des sons très courts de quelques secondes tout au plus : 3 ou 4 minutes deviennent indigestes pour playsound

    D'autre part, il n'y a pas de notification de progression possible (ce que permet Audiotract) (et ça m'embête pas mal...)

    Citation Envoyé par anapurna Voir le message
    sinon de façon dynamique si j'ai bien compris le write interviens après le play et non avant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    procedure PlaySound();
         at1.play;
         at1.write(soundData,0,playBufferSize);
    end;
    Ça, par contre c'est quelque chose auquel je n'avais pas pensé même si j'ai pu voir cette façon de faire en MODE_STREAM...
    En MODE_STATIC, j'ai plutot vu l'inverse :
    https://stackoverflow.com/questions/...ck-mode-static
    https://www.programcreek.com/java-ap...od=MODE_STATIC

    C'est carrément contre-intuitif cette affaire.
    Du coup, bon, je vais creuser de ce côté là.
    Bidouilleuse Delphi

  7. #7
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 419
    Points : 5 818
    Points
    5 818
    Par défaut
    salut

    j’avoue que moi aussi j'ai été dérouté par cette façon de faire ... j'ai donc consulté plusieurs discussions et toutes fonctionnent comme indiqué
    le pourquoi du comment je ne le connais pas
    Nous souhaitons la vérité et nous trouvons qu'incertitude. [...]
    Nous sommes incapables de ne pas souhaiter la vérité et le bonheur, et sommes incapables ni de certitude ni de bonheur.
    Blaise Pascal
    PS : n'oubliez pas le tag

  8. #8
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 037
    Points : 40 941
    Points
    40 941
    Billets dans le blog
    62
    Par défaut juste pour marqué le coup
    Bonjour,

    @LadyWasky Changement d'avatar la killeuse se transforme en gentille licorne

    ça me donne envie de changer le mien en grand Yaka
    Nom : druide.png
Affichages : 1016
Taille : 15,5 Ko
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  9. #9
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Citation Envoyé par SergioMaster Voir le message
    Bonjour,

    @LadyWasky Changement d'avatar la killeuse se transforme en gentille licorne

    ça me donne envie de changer le mien en grand Yaka
    Nom : druide.png
Affichages : 1016
Taille : 15,5 Ko
    Hahaha :p
    Le choix des couleurs n'est pas anodin : j'avoue, a travers ces couleurs, afficher mon appartenance à une certaine minorité par rapport à des attaques diffamatoires graves sur une certaine partie du forum.

    Mais en même temps, ça fait du bien de s'afficher en étant soi même et je ne vois pas comment on pourrait m'en empêcher.

    La "killeuse" était une référence à la série "Hit&Miss"

    Tant pis pour le hors sujet du topic et tant mieux si ça donne des envies de changement

    Ce grand Yaka est superbe
    Bidouilleuse Delphi

Discussions similaires

  1. Commande DOS affichée dans memo, le tout dans un thread
    Par LaurentC33 dans le forum Débuter
    Réponses: 38
    Dernier message: 31/03/2022, 09h22
  2. Réponses: 1
    Dernier message: 18/05/2017, 08h21
  3. Tout marche. Mais pas de son dans le swf
    Par Drife dans le forum ActionScript 1 & ActionScript 2
    Réponses: 0
    Dernier message: 17/04/2010, 14h24
  4. [Lenny] Pas de son du tout, independamment du logiciel
    Par MaliciaR dans le forum Debian
    Réponses: 7
    Dernier message: 02/08/2009, 17h24
  5. [J2ME]pas de son
    Par Arkan dans le forum Java ME
    Réponses: 2
    Dernier message: 04/04/2005, 15h32

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