SD card MOD S3M soundtrack player on PIC32

Show off your projects to others!
serveurperso
Posts: 36
Joined: Tue Sep 13, 2011 5:55 am
Location: Paris
Contact:

SD card MOD S3M soundtrack player on PIC32

Post by serveurperso » Sun Nov 20, 2011 5:44 pm

Accurate MOD or S3M player with all Protracker / Scream tracker 3 effects

http://www.youtube.com/watch?v=Gg9AeQXbcFM
My new FAT16/32/SDHC SDcard (FatFs) version :
http://www.youtube.com/watch?v=i3Yl0TISQBE

Can read any .MOD that fit in program memory of Uno32 (128K) or Max32 (512K)

There are thousands of quality music that can be played on this code: http://modarchive.org

46KHz 11 bits with linear interpolation and stereo PWM !!! 100% integer/fixed point DSP algorithm and circular sound buffer / file system buffer.



Source code for MPIDE and MPLAB here -> http://www.serveurperso.com/temp/

Have fun:)

Pascal
Attachments
MPIDE-Terminal.png
MPIDE-Terminal.png (17.48 KiB) Viewed 5225 times
Last edited by serveurperso on Sat Dec 24, 2011 9:55 pm, edited 37 times in total.
(French user) English is not my native language, please forgive my mistakes.

svaha
Posts: 4
Joined: Sat Nov 12, 2011 1:31 am

Re: Amiga MOD soundtrack file player on PIC32

Post by svaha » Mon Nov 21, 2011 4:06 am

Nice! I liked your Audio Spectrum Analyser as well.

serveurperso
Posts: 36
Joined: Tue Sep 13, 2011 5:55 am
Location: Paris
Contact:

Re: Amiga MOD soundtrack file player on PIC32

Post by serveurperso » Fri Nov 25, 2011 12:15 am

Large code removed (zip)
Last edited by serveurperso on Sun Dec 11, 2011 1:23 pm, edited 7 times in total.
(French user) English is not my native language, please forgive my mistakes.

zerobyte
Posts: 2
Joined: Sun Nov 27, 2011 3:08 pm

Re: Amiga MOD soundtrack file player on PIC32

Post by zerobyte » Sun Nov 27, 2011 3:18 pm

Amazing!
I tried to code a mod player on AVR XMEGA few mounths ago, it was pretty difficult especially because i used float algo to have a better sound, which finally doesnt work correctly with all mods.
Can we have a look at your source code? I'm curious to see how you use the PWM as stereo DAC.

EDIT: oh sorry, It's on .pde file... weird extension. :)

serveurperso
Posts: 36
Joined: Tue Sep 13, 2011 5:55 am
Location: Paris
Contact:

Re: Amiga MOD soundtrack file player on PIC32

Post by serveurperso » Sun Nov 27, 2011 4:44 pm

Hi, thanks:) you don't need float, fixed point DSP and multiply before divide give very good accuracy and way better performance, If you put a 16 bit DAC on my player you get exactly the sound of any tracker with "linear interpolation" setup. I use 10 bits for mantissa (#define DIVIDER 10)

It use hardware PWM feature of PIC32 :

Code: Select all


Setup :

 // 9 bits stereo PWM
 OpenTimer2(T2_ON | T2_PS_1_1, 512);
 OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
 OpenOC2(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);

 // Sampler
 ConfigIntTimer3(T3_INT_ON | T3_INT_PRIOR_3);
 OpenTimer3(T3_ON | T3_PS_1_1, F_CPU / SAMPLERATE);


extern "C" {
 void __ISR(_TIMER_3_VECTOR, ipl3) T3InterruptHandler() {
  mT3ClearIntFlag();

 for(..............

..........Mixer code.............

   // Upscale to 9 bits
   out *= 2;

   // Channel volume
   out = out * Sampler.channelVolume[channel] / 64;

   // Channel panning 0 is hard left 128 is hard right
   sumL += out * min(128 - Sampler.channelPan[channel], 64) / 64;
   sumR += out * min(Sampler.channelPan[channel], 64) / 64;
  }

  // Downscale to 9 bits
  sumL /= Mod.numberOfchannels;
  sumR /= Mod.numberOfchannels;

  // Signed to unsigned
  SetDCOC1PWM(sumL + 256);
  SetDCOC2PWM(sumR + 256);
 }
}


Sorry for me english

Pascal
(French user) English is not my native language, please forgive my mistakes.

fulvio
Posts: 19
Joined: Tue Nov 29, 2011 5:16 am

Re: Amiga MOD soundtrack file player on PIC32

Post by fulvio » Tue Nov 29, 2011 8:12 am

This is brilliant, can't wait to give this a go and add some LCD output for song name, track length, etc. Maybe even an equalizer of sorts. Thanks a million.

serveurperso
Posts: 36
Joined: Tue Sep 13, 2011 5:55 am
Location: Paris
Contact:

Re: Amiga MOD soundtrack file player on PIC32

Post by serveurperso » Tue Nov 29, 2011 8:47 am

I just finished the relationship formulas for maximum sound quality on the PIC32 hardware PWM.
BITDEPTH SAMPLERATE (and DIVIDER) are adjustables and the MOD is always played at the right frequency !

Code: Select all

#define BITDEPTH 10      // 10 bits PWM (80MHz / 1024 = 78125Hz)
#define SAMPLERATE 39063 // 78125Hz / 2
#define DIVIDER 10       // Fixed-point mantissa

// Hertz = 7093789 / (amigaPeriod * 2) for PAL
// Hertz = 7159091 / (amigaPeriod * 2) for NTSC
#define AMIGA (7093789 / 2 / SAMPLERATE << DIVIDER)
// Sampler.channelFrequency[channel] = AMIGA / amigaPeriod
(French user) English is not my native language, please forgive my mistakes.

fulvio
Posts: 19
Joined: Tue Nov 29, 2011 5:16 am

Re: Amiga MOD soundtrack file player on PIC32

Post by fulvio » Thu Dec 01, 2011 4:20 am

What kind of information/data can be extracted from the MOD to be displayed via an LCD?

fulvio
Posts: 19
Joined: Tue Nov 29, 2011 5:16 am

Re: Amiga MOD soundtrack file player on PIC32

Post by fulvio » Thu Dec 01, 2011 6:51 am

I have a Chipkit UNO32 running on Windows 7.

I'm getting the following error when Uploading to the board:

Code: Select all

c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: address 0xa0004418 of mod32.cpp.elf section `.stack' is not within region `kseg1_data_mem'
c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: address 0xa0004800 of mod32.cpp.elf section `.ramfunc' is not within region `kseg1_data_mem'
c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: Not enough space to allocate both stack and heap.  Reduce heap and/or stack size.
c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: address 0xa0004418 of mod32.cpp.elf section `.stack' is not within region `kseg1_data_mem'
c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: address 0xa0004800 of mod32.cpp.elf section `.ramfunc' is not within region `kseg1_data_mem'
c:/users/fcusumano/downloads/mpide-0022-windows-20110822/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld.exe: Not enough space to allocate both stack and heap.  Reduce heap and/or stack size.
collect2: ld returned 1 exit status
I'm using the

Code: Select all

NTRONIC3.MOD.h
header file.

serveurperso
Posts: 36
Joined: Tue Sep 13, 2011 5:55 am
Location: Paris
Contact:

Re: Amiga MOD soundtrack file player on PIC32

Post by serveurperso » Thu Dec 01, 2011 7:55 am

Can you re download the last version ? I tested It work with Mpide 0022 20110822

(Or reduce MAXCHANNELS to 16 on older version)

Pascal
(French user) English is not my native language, please forgive my mistakes.

Post Reply