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.

3pointedit

What kind of file does this create? A .WAV? Or is it a peculiar format that needs decoding on the PC?
550D on ML-roids

1%

In theory 48khz wav but I don't think its actually writing them. It just plays back the buffer in the function.

In 600D:

NSTUB(0xFF17F734, str:VOI_FactoryRecord_[VOI]_[VOI_FactoryRecord])

NSTUB(0xFF17F5B4, str:VOI_StopVoiceRecord_[VOI]_StopSemaphore)

But why does it mess with

0x5DC4 (aAJ_0x1F50_SoundDevSet_HDMI_struct_0x00_to_0x50)

Is it related to the crazy "throw music over your files" function.

QuoteYou can now add music to videos in the camera. You can copy the music that Canon provides on the EOS Digital Solution Disk to the memory card using the provided EOS Utility program. Alternately, you can add music from your computer to the memory card, again using the EOS Utility. Then on the camera, you can choose a music selection to play as background music for the video. With the music added, all you need to do is to plug the T3i/600D into a TV, pop some popcorn, and enjoy your HD videos in style.

a1ex

With latest changesets it saves WAV files. You can even add voice tags to photos.

Greg


1%

I'm running out of memory with the latest:

ASSERT: FALSE
at Memory\Memory.c:188, task beep_task
lv:1 mode:20


Magic Lantern version : v2.3.NEXT.2012Aug21.600D102
Mercurial changeset   : e5ac61e7da2b+16278f5df476+ (unified) tip
Built on 2012-08-21 21:59:59 by user@D610.
Free Memory  : 334K + 1019K

157:  5407.154 [STARTUP] too heavy... free : 1018KB
    158:  8937.274 [MEM] NG AllocateMemory 480172
    159:  8937.452 [MEM] Total = 0x8b0000, Free = 0xfe934, MaxReg = 0x54ab8
    160:  8938.398 [MEM] Num Alloc = 3543, Num Free = 335
    161:  8953.146 [STARTUP] ERROR ASSERT : Memory\Memory.c, Task = beep_task
    162:  8953.237 [STARTUP] ERROR ASSERT : Line 188
    163:  8953.276 [STARTUP] ERROR ASSERT : FALSE
    164:  8953.423 [STARTUP] startupErrorRequestChangeCBR (0x1d)
    165:  8953.476 [STARTUP] startupErrorRequestChangeCBR : ErrorSend (101, ABORT)
    166:  8953.745 [STARTUP] ASSERT : Time 2012/8/21 17:10:5




Ok, I've  fixed recording using shoot_malloc. I still get error 70 on playback.

Will this work to free the shooting buffer?
FreeMemory(wav_buf);


Also changed:

FIO_WriteFile(f, shoot_malloc(wav_buf), sizeof(wav_header) + N);

int16_t* long_buf = shoot_malloc(N*2);
if (!long_buf) { N = 48000; long_buf = shoot_malloc(N*2); }
[/quote]

Did I miss a location? I can record a whole 60 second clip but can't even play back 5s... regular beeps work.


Also get a dir err at start but pressing left/right shows the file names and lets them be selected.


I put zebras into exmem space and now I can play back a 5s file. I have 1500k free... I don't think there is any more I can free....

Tried changing file reading to exmem and then I get no ML menu. Exmem is not big enough, I guess. Is there a way to find max size or make it allocate above what canon uses? I also put back allocate memory for short tones and uncachable for file writing (made no difference either way)....

Now recording is great but for some reason playback isn't working. At least the memory problems are gone. Thanks!

miyake

600D recording is working current codes. But play is not working yet.  I will discover how to solve it on 600D.

Anyway, 600D audio forum user testing combination with Sound recording and video recording
http://www.magiclantern.fm/forum/index.php?topic=2032.msg9437#msg9437
It will crash camera, and need battery pull.
Do you know this? And another cameras don't have this issue?


a1ex

As far as I know, 600D is able to beep, so it should playback sound too (maybe you redirect the sound to headphones?)

I didn't try sound recording and video recording at the same time, so it's likely to run into trouble with this.

scrax

I've just tried on last code from miyake and it's working ok now, but since i use Hold->Play feat for image review voice tags can't be used.
Is it possible to have an option to enable it in PLAY mode too?

If there is no audio file associated with the shown pic SET will record Voice Tag, if present it will play it (maybe an icon should be perfect to see the audio file already present) and MENU button can be used to delete them from PLAY mode.
This will also permit to take photos at an events and then tag them after the day maybe with someone who knows the subjects better.
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

This would require a way to find out which file is selected in playback mode. If this can be done, the icon and playback are easy to implement.