Page 1 of 1

Need help for audio datatype.

Posted: Fri Mar 01, 2013 1:54 pm
by AmiDARK
Hi,

I encounter a problem on which I have no solution.
Due to the structure of the AmiDARK Engine, audio is defined this way :

1. Function to load an object : DELoadSound( File, ID )
2. Function to play/pause/resume/stop object : DEPlaySound( ID ), DEPauseSound( ID ), DEResumeSound( ID ), DEStopSound( ID )
3. Function to delete object : DEDeleteSound( ID )

I can load an audio using datatype, delete it without problem.
The problem is when I want to play it.
I copy the functions there to show you :

Code: Select all

void DELoadSound( char *szFilename, int iID ){
//  ULONG res;
//  uint32 longueur ;
  if ( iID > 0 ){
    if ( iID < 257 ){
      if ( DESoundExist( iID ) == 0 ){
        if( DEFileExist( szFilename ) == TRUE ){
            AESound[ iID ].ObjectPTR = IDataTypes->NewDTObject( (STRPTR)szFilename,
                                                                DTA_SourceType, DTST_FILE,
                                                                DTA_GroupID, GID_SOUND,
                                                                SDTA_Volume, 63,
//                                                                SDTA_SignalTask, (ULONG)IExec->FindTask(NULL),
//                                                                SDTA_SignalBitMask, END_SOUND_SIGNAL,
                                                                TAG_END );
          if ( AESound[ iID ].ObjectPTR != NULL  ){
            AESound[ iID ].Exist = TRUE;
            AESound[ iID ].Loop = FALSE;
            AESound[ iID ].Playing = 0;
            AESound[ iID ].FileName = LCreateString( 256 );
            LCopyString( szFilename, AESound[ iID ].FileName );
            AESound[ iID ].Audio3D = 0 ; // This sound IS NOT a 3D Audio sound.
           }else{
            printf( "DELoadSound Warning : Object not created\n" );
            AESound[ iID ].Exist = FALSE;
           }
         }
       }
     }
   }
 }

void DEPlaySound( int iID ){
  if ( DESoundExist( iID ) == 1 ){
    if ( AESound[ iID ].Playing != 0 ){
      DEStopSound( iID );
     }
    mydtt.MethodID = DTM_TRIGGER;
    mydtt.dtt_GInfo = NULL;
    mydtt.dtt_Function = STM_PLAY;
    mydtt.dtt_Data = NULL;
      AESound[ iID ].dores = IDataTypes->DoDTMethodA( AESound[ iID ].ObjectPTR, NULL, NULL, (Msg)&mydtt );
      IExec->Wait( SIGBREAKF_CTRL_C );
    AESound[ iID ].Playing = 1;
   }
 }
So, everything compiles ok in the libAmiDARK.a file.
When I use these functions from a fresh project (that'll use the libAmiDARK.a lib), here is the problem I encounter.

1. With the line "IExec->Wait( SIGBREAKF_CTRL_C );" removed : No audio playback.
2. With the line "IExec->Wait( SIGBREAKF_CTRL_C );" not removed : audio playbak but program lock infinitely. and I cannot quit the application nor doing anything from the moment the sample started to play.

Here the source code I use to test the DEPlaySound function :

Code: Select all

#include "libamidark.h"
int InKey;
void DarkLoop( void ){  
  // Setup Display.
  DESetDisplayMode( 640, 480, 32 );
  DESyncOn();
  DESyncRate( 60 );
  // Load the 4 samples using DataTypes.
  DELoadSound( "Medias/oceanwave.wav", 1 );
  DELoadSound( "Medias/break.wav", 2 );
  DELoadSound( "Medias/DREAM.WAV", 3 );
  DELoadSound( "Medias/electricarc.wav", 4 );
  DELoadImageEx( "Medias/AmiDARK_Engine_Logo v2.png", 1, 1 );
  InKey = 0;
  while( !DELoop() ){
    DECls();
    DESetCursor( 0, 0 );
    DEPrint( "AmiDARK Engine now play Audio Sounds using DATATYPES" );
    DEPrint( "Press default QUIT KEY to stop this demonstration example." );
    DEPrint( " " );
    DEPrint( "Press 1 to play OceanWave.wav" );
    DEPrint( "Press 2 to play Break.wav" );
    DEPrint( "Press 3 to play Dream.wav" );
    DEPrint( "Press 4 to play ElectricArc.wav" );
    // Keyboard key 1 to 4 start replay of a sound.
    InKey = DEScancode(); InKey--;
    if ( InKey > 0 ){
      if ( InKey < 5 ){
        DEPlaySound( InKey );
       }
     }
    DEPasteImageEx( 1, DEBitmapWidth( 0 ) - ( DEImageWidth( 1 ) + 4 ), 4, 1 );
    DESync();
   }
  // We delete sounds from memory.
  for ( InKey = 0; InKey < 5; InKey++ ){
    DEStopSound( InKey );
    DEDeleteSound( InKey );
   }
 }
As you can see, I load 4 samples.
when you press a key from 1-4 it start play a sample.
So, due to this way of working, I cannot use Wait functions to wait the sound finished.
(do you see in a game a ship fire a projectyle and the game pause until the sound is finished ? :p)
So, Does someone have an idea on how I can fix this problem ?

Thank you.

Kindest Regards,
AmiDARK

Re: Need help for audio datatype.

Posted: Fri Mar 01, 2013 11:15 pm
by tonyw
I thought Thomas Rapp answered you pretty well on amigaworld.net. It looks as though you are never yielding control to any other process.

You have to rewrite your program so that it is event-driven.

Re: Need help for audio datatype.

Posted: Fri Mar 01, 2013 11:33 pm
by AmiDARK
I don't think my program is the only cause, otherwise all library that uses AHI may not work.
So why Ptreplay.library work with my application when direct datatype/AHI use don't ?