How to play custom WAV data

Started by a1ex, July 30, 2012, 09:29:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

a1ex

StartPlayWaveData - plays a test WAV file stored in ROM.

550D: WAV data is at ff45715c - contains RIFF and WAVE strings.

If memory resource is already allocated, the code does this:

if audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/ != 0 /*NE*/:
    AJ_guess_sortof_a_copy__FROM.R1__TO.R0__LEN.R2(audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/, 0xff45715c: pointer to 0x46464952, 0x2ee24)
    SamplingRate_bit_channel(0xbb80, 0x10, HALFWORD(*0xFF457172), 0x2ee00)


0xff064eb8 SamplingRate_bit_channel:


con_puts('\nSamplingRate = %d, bit = %d, channel = %d\n', arg0, arg1, arg2) => ret_con_puts_FF064ED8
audio_struct.off_0x4 /*0x26D0*/ = BYTE(arg2)
audio_struct.off_0x60 /*0x272C*/ = arg3
audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/ = 44 + audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/
SetSamplingRate_FSamplingRate(arg0, 0x1)
src:ASIF\ASIF.c()
AJ_PowerAudioOutput()
Audio\AudioIC.c_hHPTimer(0x3)
*(-32 + sp0) = @called_by:SamplingRate_bit_channel
StartASIFDMADAC(44 + audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/, arg3, 44 + audio_struct.continuous_mem_buf /*off_0x2C, 0x26F8*/, arg3)


StartASIFDMADAC uses the following DIGIC registers:
0xC092020C, 0xC0920220, 0xC05000xx.

a1ex

This code seems to play a 480 Hz test tone (550D 109), and it's pretty loud :)


int N = 48000;
int16_t* buf = AllocateMemory(N*2);
for (int i = 0; i < N; i++) buf[i] = ((i/100) % 2) ? 32767 : -32767;
MEM(0x26F8) = buf;
PlayWaveData(48000, 0x10, 2, 48000);

NSTUB(0xff064eb8, PlayWaveData) // args: sampling rate, bit, channel, size maybe; wav data ptr is at 0x26F8


Enjoy!

cgapeart


a1ex

And with a bit of luck, I hope it will work on 5D2/50D/500D, which don't have any StartPlayWaveData function, and will probably fix the limited number of beeps in 60D.

Michael Zöller

Veeery interesting. Great find, a1ex! Maybe this is a possible direction: http://ltcsmpte.sourceforge.net/ .. :)
neoluxx.de
EOS 5D Mark II | EOS 600D | EF 24-70mm f/2.8 | Tascam DR-40

a1ex

Code for 5D2 2.1.2 - but only works after playing a movie with audio.


    int N = 48000;
    int16_t* buf = AllocateMemory(N*2);
    for (int i = 0; i < N; i++) buf[i] = ((i/100) % 2) ? 32767 : -32767;
    PowerAudioOutput();
    MEM(0xC092011C) = 4; // SetASIFADCModeSingleINT16
    StartASIFDMADAC(buf, 48000, buf, 48000, asif_cbr, 48000);

    NSTUB(0xff85a890, PowerAudioOutput)
    NSTUB(0xff85828c, StartASIFDMADAC)

ilguercio

Give me good news :P
That would mean we can sync audio a bit easier and that some audio chip is somewhere inside our 50D.
Keep on going.
Canon EOS 6D, 60D, 50D.
Sigma 70-200 EX OS HSM, Sigma 70-200 Apo EX HSM, Samyang 14 2.8, Samyang 35 1.4, Samyang 85 1.4.
Proud supporter of Magic Lantern.

a1ex

Yes, I'm almost there with playback on 5D2. As soon as I'll be able to play a sound without having the movie player configure the audio chip, we'll try it on 50D.

The beep is MUCH louder than autofocus beep (and volume is configurable, of course).

a1ex

Okay, working code for 5D2 and probably portable to 50D/500D, no idea about 600D:


    int N = 48000;
    int16_t* buf = AllocateMemory(N*2);
    for (int i = 0; i < N; i++) buf[i] = i > 4800 ? 0 : ((i/50) % 2) ? 32767 : -32767;
   
    SetSamplingRate(48000, 1);
    MEM(0xC0920210) = 6; // SetASIFDACModeInterleaveINT16
    PowerAudioOutput();
    SetAudioVolumeOut(2); // 0...5
    StartASIFDMADAC(buf, 48000, buf, 48000, asif_cbr, 48000);


TODO:
* How to specify playback duration? (the above code beeps twice)
* How to switch to a new buffer when playback stops? (maybe with asif_cbr)

ilguercio

Canon EOS 6D, 60D, 50D.
Sigma 70-200 EX OS HSM, Sigma 70-200 Apo EX HSM, Samyang 14 2.8, Samyang 35 1.4, Samyang 85 1.4.
Proud supporter of Magic Lantern.


ilguercio

Canon EOS 6D, 60D, 50D.
Sigma 70-200 EX OS HSM, Sigma 70-200 Apo EX HSM, Samyang 14 2.8, Samyang 35 1.4, Samyang 85 1.4.
Proud supporter of Magic Lantern.

3pointedit

Can it make a ringtone? You could sell ringtones for MagicLantern  :P fund the program or play Star Wars theme...
550D on ML-roids

Greg


a1ex

You can play any WAV file in theory.

So if you don't want to carry a big and clunky music player, you could just plug the headphones in the A/V jack and listen :)

On-topic: this can open the doors to voice recording feature, which was requested a few times, but I had no clue where to start to implement it.

scrax

Quote from: a1ex on August 06, 2012, 01:21:28 PM

On-topic: this can open the doors to voice recording feature, which was requested a few times, but I had no clue where to start to implement it.

This is great news, I'll use it for saving info with the pics like names of people shooted, notes on the pic, places etc...
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

3pointedit

a1ex I was wondering that (audio notes) when I wrote the OT comment (sorry), but doesnt that overlap with the picture event? I guess it would be available between shots. That could be a real killer app for news photographers!
550D on ML-roids

1%

Quote
On-topic: this can open the doors to voice recording feature, which was requested a few times, but I had no clue where to start to implement it


600D firmware mentions a voice recorder. Maybe if you figure out how to record sound only,  600D will have audio free of canon meddling.

scrax

Quote from: 3pointedit on August 06, 2012, 02:40:56 PM
a1ex I was wondering that (audio notes) when I wrote the OT comment (sorry), but doesnt that overlap with the picture event? I guess it would be available between shots. That could be a real killer app for news photographers!
Yes between shot I was expecting it, You take a pic, then from PLAY mode pressing LV button (for exmple) ML records an audio file with the same name of the pic selected.
Some sort of that function is already in high end cameras for photojournalist.
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

3pointedit

If the camera could play back audio files, perhaps small audio tips could be added to the documentation. So that a user could be directed to shortcuts or even ML training/tutorials while using the camera. That is a sequence of audio files could play depending on the feature in use...
Good for kids, possibly handy for non-English readers/speakers too.

But I guess we are only looking at record function here, not playback?
550D on ML-roids

scrax

 :o Audio help for blank photographers?  ::)
:D
In what language? I think that is really way more easy for a non English user to read and use google translate (at least) than trying to understand something spoken.
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

a1ex

Voice recording works!!!

I'm able to record 30-second mono clips at 48 KHz, 16-bit (maybe even longer), and play them back.

Code for "don't click me":


int rec_done = 0;
static void asif_stop_cbr()
{
    rec_done = 1;
    info_led_blink(3,50,50);
}

void normalize_audio(int16_t* buf, int N)
{
    int m = 0;
    for (int i = 0; i < N; i++)
        m = MAX(m, ABS(buf[i]));
    for (int i = 0; i < N; i++)
        buf[i] = buf[i] * 32767 / m;
}

void run_test()
{
    int N = 48000*30;
    int16_t* buf = shoot_malloc(N*2);
    if (!buf) return;

    msleep(2000);
   
    info_led_on();
    rec_done = 0;
    SetSamplingRate(48000, 1);
    MEM(0xC092011C) = 4; // SetASIFDACModeSingleINT16
    StartASIFDMAADC(buf, N, 0, 0, asif_stop_cbr, N);
    while (!rec_done) msleep(100);
    info_led_off();
    msleep(1000);
   
    normalize_audio(buf, N);
    play_beep(buf, N);
}



5D2 212:

NSTUB(0xff8580e8, StartASIFDMAADC)


Jason_Jung


a1ex

I expect it to work on everything expect 50D, but only tried on 5D2.

1%

Works on 600D for me. Audio has to be turned on and powered up. Started monitoring through the speaker when I had it disabled.