View Single Post
Old 21 December 2019, 15:22   #93
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
@phx I've installed the player (latest from aminet, with unmodified ptplayer.h header!) into my program and I have issues/questions

- the module replay works fine. I have created a custom module where some bass notes are played wrong though. Play okay in VLC. Doesn't matter much... Do you want to look at it? I can zone it.
- I'm not able to play sounds properly. Do you have a small example on how to do that? I've used the structure and all but nothing plays (it stops the music when I play a sound)
- I'd like to be able to stop the music / play the music only once. Possible?
- I'd like to play sounds without the music started. When I set mt_Enable = 1 before playing a module, I have a trashed sound playing, then nothing.

Quote:
Sound effect samples have to be in the same format as the music samples, which means: make sure the first two bytes are cleared! The player uses the first two bytes for idle-looping.
same format means? I'm using a custom python script to convert .wav files to 8 bits, adding 2 zeroes at start. Is that unsigned/signed raw?

Code:
import subprocess,os,glob

outdir = "amiga/sfx"
for wav_file in glob.glob(os.path.join("../sound/*.wav")):
    raw_file = os.path.join(outdir,os.path.splitext(os.path.basename(wav_file))[0]+".raw")
    cmd = ["sox",wav_file,"--bits","8","-r","16000","--encoding","unsigned-integer",raw_file]
    subprocess.check_call(cmd)
    with open(raw_file,"rb") as f:
        contents = f.read()
    with open(raw_file,"wb") as f:
         f.write(b"\x00"*2)
         f.write(contents)
here's my sample loading code (C++):

Code:
static UWORD hardware_period(int bytes, int hertz)
{
  return ((UWORD) 100000000L / (bytes*hertz*28));
}

SoundPlay::SampleNode *SoundPlay::load(const MyString &filename, int key, bool)
{
  init();

  SoundPlay::SampleNode *rc = 0;

  SampleNode sn;
  MyFile sf(filename);

  StreamPosition sz = sf.size();
  if (sz>0)
    {
      sn.cvt.sfx_ptr = AllocMem(sz,MEMF_CHIP);
      if (sn.cvt.sfx_ptr == nullptr)
	{
	  abort_run("Cannot allocate %d bytes",sz);
	}
    }
  else
    {
      abort_run("Cannot read sound file %s",filename);
    }
  sn.cvt.sfx_len = sz / 2;
  sn.cvt.sfx_per = hardware_period(sz,16000);
  sn.cvt.sfx_vol = 50;
  sn.cvt.sfx_cha = -1;
  sn.cvt.sfx_pri = 1;
  sf.read_bytes(sn.cvt.sfx_ptr,sz);

  std::pair<SampleList::iterator,bool> rval = sample_node.insert(std::make_pair(key,sn));

  SampleList::iterator it = rval.first;
  rc = &(it->second);

  return rc;
}
I'm playing like this: mt_playfx(custom_base,&sn.cvt);
jotd is offline  
 
Page generated in 0.05290 seconds with 11 queries