Click Here
home features news forums classifieds faqs links search
6155 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
22 crawler(s) on-line.
 95 guest(s) on-line.
 0 member(s) on-line.



You are an anonymous user.
Register Now!

/  Forum Index
   /  Amiga Development
      /  *Urgent* Need help for audio datatype.
Register To Post

PosterThread
AmiDARK 
*Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 12:29:02
#1 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

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 :

Quote:

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 :
Quote:

#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

Last edited by AmiDARK on 01-Mar-2013 at 01:16 PM.
Last edited by AmiDARK on 01-Mar-2013 at 12:29 PM.

 Status: Offline
Profile     Report this post  
thomas 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 13:20:36
#2 ]
Super Member
Joined: 28-May-2003
Posts: 1155
From: Germany

@AmiDARK

The STM_PLAY trigger starts to play the sound in the background. No need to wait. The sound stops when enother trigger is sent to the same object. You don't need to stop the sound, it is automatically restarted when you send another STM_PLAY. It is also stopped during dispose, so you don't need to stop it there, either.

I don't see any obvious mistake in your code. But I cannot judge about all the DE#? functions. Could it be for example that DEScancode does not wait for a key press but returns immediately, so that you keep sending STM_PLAY triggers to the sound object repeatedly?

Another problem could be with your AHI settings. If you play music in parallel to your program, the music might mute the sound if there are not enough channels set up in AHI prefs.

_________________
Email: thomas-rapp@web.de
Home: thomas-rapp.homepage.t-online.de

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 14:53:37
#3 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

Thomas,

Quote:
The STM_PLAY trigger starts to play the sound in the background. No need to wait. The sound stops when enother trigger is sent to the same object. You don't need to stop the sound, it is automatically restarted when you send another STM_PLAY. It is also stopped during dispose, so you don't need to stop it there, either.

Ok. I Understand but user can "stop" a sound output and restart it later so the DEStopSound command is important.

Quote:
I don't see any obvious mistake in your code. But I cannot judge about all the DE#? functions. Could it be for example that DEScancode does not wait for a key press but returns immediately, so that you keep sending STM_PLAY triggers to the sound object repeatedly?

Checked my DEScanCode() function and it ask a key only when requested. so the problem is not here.

Quote:
Another problem could be with your AHI settings. If you play music in parallel to your program, the music might mute the sound if there are not enough channels set up in AHI prefs.

I understand this and I'll check for this later.

Thank you for your answer


EDIT :
I've made more tests.
I have removed the IExec-Wait() call and I have modified the main sound test source code this way :
Quote:
#include "libamidark.h"

int InKey, OldKey;

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;
OldKey = 0;

while( !DELoop() ){
DECls();
DESetCursor( 0, 0 );
DEPrint( "AmiDARK Engine now play Audio Sounds using DATATYPES" );
DEPrint( "Press default QUIT KEY to stop replay music." );
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.
OldKey = InKey;
InKey = DEScanCode(); InKey--;
if ( InKey > 0 ){
if ( InKey < 5 ){
if ( OldKey != InKey ){ // To avoid multiple request.
DEPlaySound( InKey );
DEPrint( " " );
DEPrint( "Requested playing sound !" );
IExec->Wait( (uint32)0 );
}
}
}
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 );
}
}

With OldKey/InKey you can no more request twice for the same sound.
When I request for a sound, with the line IExec->Wait( (uint32)0 ), the sound is played but application remain locked at the IExec->Wait( (uint32)0 ); line.
if I remove the IExec->Wait( (uint32)0 ), the sound is not played but application is not locked. Can quit it.

So problems don't came from the way I handle the DataType.
But Maybe, there is something to do with MiniGL ?
Maybe it lock hardware preventing from using audio ?

Kindest Regards,
AmiDARK

Last edited by AmiDARK on 01-Mar-2013 at 03:12 PM.

 Status: Offline
Profile     Report this post  
itix 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 15:16:33
#4 ]
Elite Member
Joined: 22-Dec-2004
Posts: 3398
From: Freedom world

@AmiDARK

Audio.datatype spawns another process to play sample. Perhaps your program is busylooping and audio process never gets a chance to run?

In general I cant recommend using datatypes to load nor play samples.

_________________
Amiga Developer
Amiga 500, Efika, Mac Mini and PowerBook

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 15:19:05
#5 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

itix,
It's what I suspect.
Is there any OS function I can call on each frame to be sure that background process can run correctly ?

Kindest Regards,
AmiDARK

 Status: Offline
Profile     Report this post  
thomas 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 15:39:23
#6 ]
Super Member
Joined: 28-May-2003
Posts: 1155
From: Germany

@AmiDARK

A properly written program should be event driven, i.e. the inner loop should begin with a Wait() and then react on the received signals.

However, to make it easy for you, you could try something like this:

Quote:

OldKey = InKey;
InKey = DEScanCode(); InKey--;
while (InKey == OldKey) {
IDOS->Delay (1);
InKey = DEScanCode(); InKey--;
}


This is a workaround, not a solution. You should add events to your engine.

_________________
Email: thomas-rapp@web.de
Home: thomas-rapp.homepage.t-online.de

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 16:25:02
#7 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

thomas,
As I'm not really familiar with "events", I don't see the need to *add* events ...
I only want my engine to be *system friendly*...
More to this .. I don't know what/which events I may add ... and to do ... what ?
Do you understand my though ?

Kindest Regards,
AmiDARK

 Status: Offline
Profile     Report this post  
thomas 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 16:41:27
#8 ]
Super Member
Joined: 28-May-2003
Posts: 1155
From: Germany

@AmiDARK

In order to make your application system-friendly you have to Wait() for something. In the current case, you have to Wait() for a key press. Either DEScancode or DELoop may not return until there is something to do or something has changed.

In a multitasking environment a busy loop like

while (oldkey == newkey)
newkey = readkey();

is not allowed.

_________________
Email: thomas-rapp@web.de
Home: thomas-rapp.homepage.t-online.de

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 16:44:28
#9 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

@thomas,
you've misunderstood my source code

DEScanCode() get the last key GLUT get in buffer
It wait for nothing ...
if no key is pressed during last rendered frame, DEScanCode simply return 0.
The main loop is :
Quote:
while( !DELoop() ){
DESync();
}


Where DESync() jump in GLUT Main loop, do all stuff and then escape from GLUT Main loop to came back in the loop.
There is NO WAIT for keyboard.
DELoop() return is 1 until GLUT get a CTRL+C or EscapeKey or windows close button event... Where it become 0 and then the loop stop and the program finish.

Kindest Regards,
AmiDARK

Last edited by AmiDARK on 01-Mar-2013 at 04:46 PM.

 Status: Offline
Profile     Report this post  
TheAMIgaOne 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 17:12:10
#10 ]
Cult Member
Joined: 10-Jan-2004
Posts: 776
From: United Kingdom

@AmiDARK

Glut could be taken up the time and not allow the audio task to run, time manangement should be at your level and not glut, I think glut has call backs for keyboard funcs. So let your code look for signals, maybe even use (which Ive used in a Wb game) setsignal(0l,0l) rather than wait, its non-blocking so will take up the cpu, but may work better for a game.

_________________
Cross-developer on Windows, OS3, OS4, Linux; Current Projects:-
Nephele Cloud App OS4
UserProfile System OS4
AmigaOneXE OS4.1.6

TaoSoftwareBlog Youtube

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 17:22:56
#11 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

@TheAMIgaOne
Effectively, after checking the MiniGL/glut source code, it takes care of intuition events, and IO keyboard events... But nothing more

Concerning SetSignal, thank you for your idea...
but IExec->SetSignal( 0L, 0L ).... Didn't fix the issue :'(

Kindest Regards,
AmiDARK

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 17:42:49
#12 ]
Elite Member
Joined: 9-Jun-2004
Posts: 13047
From: Norway

@AmiDARK

Quote:
As I'm not really familiar with "events", I don't see the need to *add* events ...
I only want my engine to be *system friendly*...
More to this ..


The idea is that your program wakes up when there some thing to do, insted of looking for things to do when there is nothing to be done.

Quote:
I don't know what/which events I may add ... and to do ... what ?
Do you understand my though ?


There is timer events, msg ports events, keyboard events, and you can create your own, lets say you wont to de complicate your main loop by moving other process cyles into a task or process, then you might wont to singal that task or process when its time to do some thing.

Lets say you wont to play sounds then you might assign this to process and have it wake up at some interval to fill up some audio buffer or some thing like that.

Last edited by NutsAboutAmiga on 01-Mar-2013 at 05:51 PM.
Last edited by NutsAboutAmiga on 01-Mar-2013 at 05:46 PM.

_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
AmiDARK 
Re: *Urgent* Need help for audio datatype.
Posted on 1-Mar-2013 22:54:12
#13 ]
Regular Member
Joined: 28-Mar-2007
Posts: 469
From: South France

I try to understand how message/events works ... but I don't understand the interest ... Messages/Events are not tasks running in the background. Not ? When my AmiDARK Engine application work in windowed mode, you can access your OS and everything work fine (excepted it's a bit slower due to 3D rendering) ... But nothing is locked ...

More to this, why the Ptreplay.library work perfectly with the AmiDARK Engine... This library also use AHI ...

I'm sorry but it's a lock for me ... I don't understand.

Last edited by AmiDARK on 01-Mar-2013 at 10:55 PM.

 Status: Offline
Profile     Report this post  

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle