Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
110 user(s) are online (101 user(s) are browsing Forums)

Members: 0
Guests: 110

more...

Support us!

Headlines

 
  Register To Post  

AHI question [SOLVED]
Just can't stay away
Just can't stay away


See User information
I'm trying to add sound to my 3D Swingball game, and I have some problems. The amiga-specific sound code looks like this:

#include <stdio.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <devices/ahi.h>


#include "audio.h"
#include "audio_amiga.h"


struct MsgPort    *AHImp_sound     NULL;
struct AHIRequest *AHIios_sound[nosamples];
struct AHIRequest *AHIio_sound     NULL;
BYTE               AHIDevice_sound = -1;

void Amiga_FreeAhi()
{
    if(!
AHIDevice_sound)
        
IExec->CloseDevice((struct IORequest *)AHIio_sound);
    
int i;
    for(
0nosamplesi++)
        
IExec->FreeSysObject(ASOT_IOREQUESTAHIios_sound[i]);
    
IExec->FreeSysObject(ASOT_IOREQUEST, (struct IORequest *)AHIio_sound);
    
IExec->FreeSysObject(ASOT_PORTAHImp_sound);
    
    
audioison 0;
}

void Amiga_InitAhi()
{
    if(
audioison)
    {
        
printf("Error: Audio already is on!\n");
        return;
    }
    if((
AHImp_sound IExec->AllocSysObjectTags(ASOT_PORTTAG_DONE)) != NULL)
    {
           if((
AHIio_sound = (struct AHIRequest *) IExec->AllocSysObjectTags(ASOT_IOREQUEST,
                                                                           
ASOIOR_ReplyPortAHImp_sound,
                                                                           
ASOIOR_Size,sizeof(struct AHIRequest),
                                                                           
TAG_DONE)) != NULL)
           {
              
AHIio_sound->ahir_Version 4;
              
AHIDevice_sound IExec->OpenDevice(AHINAME,0,(struct IORequest *)AHIio_sound,0);
        }
      }

      if(
AHIDevice_sound)
      {
        
printf("Unable to open %s/0 version 4\n",AHINAME);
        
Amiga_FreeAhi();
        
audioison 0;
        return;
      }

    
int i;
    for(
0nosamplesi++)
    {
          
AHIios_sound[i] = (struct AHIRequest *)IExec->AllocSysObjectTags(ASOT_IOREQUESTASOIOR_Duplicate, *AHIio_soundTAG_DONE);
      
        
AHIios_sound[i]->ahir_Std.io_Message.mn_Node.ln_Pri 127;
        
AHIios_sound[i]->ahir_Std.io_Command  CMD_WRITE;
        
AHIios_sound[i]->ahir_Std.io_Data     samples[i]->data;
        
AHIios_sound[i]->ahir_Std.io_Length   samples[i]->data_size;
        
AHIios_sound[i]->ahir_Std.io_Offset   0;
        
AHIios_sound[i]->ahir_Frequency       samples[i]->sample_rate;

        if(
samples[i]->bits_per_sample == 8)
            
AHIios_sound[i]->ahir_Type        AHIST_M8S;
        else
            
AHIios_sound[i]->ahir_Type       AHIST_M16S;
        
        
AHIios_sound[i]->ahir_Volume          0x10000;          // Full volume
        
AHIios_sound[i]->ahir_Position        0x8000;           // Centered
        
AHIios_sound[i]->ahir_Link            NULL;
    }
    
Amiga_PlaySample(0);
    
Amiga_PlaySample(0);
    
    
audioison 1;
}

void Amiga_PlaySample(int s)

    if(
IExec->CheckIO((struct IORequest *) AHIios_sound[s]) == NULL)
    {
        
printf("Sample still playing, aborting IO...\n");
        
IExec->AbortIO((struct IORequest *) AHIios_sound[s]);
        
IExec->WaitIO((struct IORequest *) AHIios_sound[s]);
    }
    
IExec->SendIO((struct IORequest *) AHIios_sound[s]);
}


The problem is this: In the middle of the game, I want to be able to abort playing a certain sample when another one pops up. Hence the CheckIO, AbortIO and WaitIO in the Amiga_PlaySample() function. But for some reason it doesn't work. CheckIO never returns NULL as expected, and SendIO messes up, so sound stops completely.

As you can see, I have inserted two test lines to the InitAhi() function, and here it "works" (it correctly prints "Sample still playing...(etc)".

What am I doing wrong??


Edited by alfkil on 2012/10/20 21:34:01
Go to top
Re: AHI question
Just can't stay away
Just can't stay away


See User information
[SOLVED]

For some reason, I need to reset the ahir_Std.io_Length each time before calling SendIO. Problem hereby solved! :)

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project