Suggestion for squarewave/Chipmusic

support for the ARM toolchain
Post Reply
AAG123
Posts: 1
Joined: Fri Mar 01, 2013 9:50 pm

Suggestion for squarewave/Chipmusic

Post by AAG123 » Fri Mar 01, 2013 11:32 pm

Hi

I'm just starting out with DS programmming - and making use of a previously failed project with YM (Atari ST/spectrum/amstrad) chipmusic (a YM file is a registered dump of the YM2149 sound regsisters, taken at 50hz).

As a proof of concept - I've parsed the YM file (XENON.YM from Atari ST) - and extracted the frequency/volumes of the 3 channels. (The ym2149 mixer for a chanel could be made to output when TONE, NOISE or Tone&Noise were selected - so I've generated a 4th chanel to emualte the noise).

Code: Select all

int AVol[ymBufferLen] = {10,10,10,
int AFreql[ymBufferLen] = {XX,XX,XXX
BFreq,BVol. CFreq, CVol. DFreq, DVol
The main code looks like this

Code: Select all

#include <nds.h>
#include <stdio.h>

#include "d-vol.h"
#include "vols.h";

volatile int pos = -1;
volatile int channelA=0;
volatile  int channelB=0; 
volatile int channelC=0;
volatile int channelD=0;



void timerCallBack()
{
	if (pos < ymBufferLen)
	{
		u16 freq = (2 * 1000 * 1000) / (2 *  AFreq[pos]);
		soundSetFreq(channelA,freq);
		soundSetVolume(channelA, Vols[AVol[pos]]);

		freq = (2 * 1000 * 1000) / (2 *  BFreq[pos]);
		soundSetFreq(channelB,2 * freq);
		soundSetVolume(channelB, Vols[BVol[pos]]);
		
		freq = (2 * 1000 * 1000) / (2 *  CFreq[pos]);
		soundSetFreq(channelC,freq);
		soundSetVolume(channelC, Vols[CVol[pos]]);

		if (DFreq[pos] == 0)
			soundSetVolume(channelD,0);
		else
		{
			 freq = (2 * 1000 * 1000) / (2 *  DFreq[pos]);
			soundSetVolume(channelD, Vols[DVol[pos]]);
		}

		pos++;	
	}
}


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	consoleDemoInit();

	float maxvol=Vols[15];
	for (int i = 0; i<= 15; i++)
	{
		Vols[i] = ((255/4)/maxvol) * Vols[i];
	}
		
	soundEnable();	

	channelA = soundPlayPSG(DutyCycle_50, 1, 0, 64);
	channelB = soundPlayPSG(DutyCycle_50, 1, 0, 64);
	channelC = soundPlayPSG(DutyCycle_50, 1, 0, 64);
	channelD =soundPlayNoise (500,0, 64);

	timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(50), timerCallBack);

	pos = 0;

	while(pos < ymBufferLen) 
	{	
		swiWaitForVBlank();
			
		iprintf("\x1b[10;0Hcc pos = %d of %d",pos,ymBufferLen-1 );
	}
	soundKill(channelA);
	soundKill(channelB);
	soundKill(channelC);
	soundKill(channelD);
	soundDisable();
	return 0;
}



Is there a better way of doing the sound updates?

From what I can unserstand of the lindns source code - the soundXXX perform some inter-process comms to the ARM7 side to actually update the sound registers.

Is there any way of making the above code more effecient/a way of updating frequency/volume for the 4 channels at once.

Would some custom arm7 code be needed? Any suggestions gratefully received.

Thanks

Andy

PS: I'll work on a proper file selector/ym loader on the native DS - the lareg arrays were just for proof of concept.

Demo source attached (build from msys command line - and the original YM file.) The DS sounds very similar to that of that produced by a YM player.

YM players available from
ST Sound http://leonard.oxg.free.fr
ay_emul http://bulba.untergrund.net/emulator_e.htm
Attachments
ymtest2.zip
(20.66 KiB) Downloaded 493 times

sverx
Posts: 94
Joined: Wed Aug 12, 2009 2:56 pm
Location: github.com/sverx
Contact:

Re: Suggestion for squarewave/Chipmusic

Post by sverx » Fri Mar 08, 2013 12:12 pm

With custom ARM7 code and using one of the user FIFO queues you could send a single message from ARM9 to perform everything at once, but I bet it won't make a big difference anyway...

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests