Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this lib just support channels = 2? #17

Open
sinkinben opened this issue Feb 5, 2024 · 5 comments
Open

Does this lib just support channels = 2? #17

sinkinben opened this issue Feb 5, 2024 · 5 comments

Comments

@sinkinben
Copy link

I have noticed that:

struct adpcm_context {
    struct adpcm_channel channels [2];
    int num_channels, lookahead, noise_shaping;
};

and piece of code in adpcm_converter:

if (WaveHeader.NumChannels < 1 || WaveHeader.NumChannels > 2)
    supported = 0;

Is it possible to support channels = {4, 6, 8} as input?

@dbry
Copy link
Owner

dbry commented Feb 5, 2024

At this point the library only handles 1 or 2 channels, although it would probably wouldn't be too hard to fix that.

However, the reason I probably never implemented that is that I have never heard of the format supporting more than 2 channels. For example, if I try to encode a multichannel WAV file into adpcm_ima_wav using FFmpeg I get this message:

[adpcm_ima_wav @ 0x62c5a626c980] only stereo or mono is supported

Of course it would be possible to just force a higher number of channels, but the resulting files probably would not be playable by any existing software. Have you seen multichannel IMA ADPCM files in the wild? What do you have in mind?

Thanks!

@sinkinben
Copy link
Author

sinkinben commented Feb 6, 2024

This is my testing command with ffmpeg:

> ./ffmpeg -i /e/workspace/temp-tuanjie/Assets/test6.wav  -f wav -acodec adpcm_ima_wav ./adpcm-multi-channels.wav

Input #0, wav, from 'E:/workspace/temp-tuanjie/Assets/test6.wav':
  Duration: 00:00:05.84, bitrate: 4233 kb/s
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 5.1, s16, 4233 kb/s
File './adpcm-multi-channels.wav' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> adpcm_ima_wav (native))
Press [q] to stop, [?] for help
Output #0, wav, to './adpcm-multi-channels.wav':
  Metadata:
    ISFT            : Lavf60.20.100
  Stream #0:0: Audio: adpcm_ima_wav ([17][0][0][0] / 0x0011), 44100 Hz, stereo, s16p, 352 kb/s
      Metadata:
        encoder         : Lavc60.38.100 adpcm_ima_wav
[out#0/wav @ 000002257a65ac40] video:0KiB audio:254KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.036141%
size=     254KiB time=00:00:05.83 bitrate= 356.6kbits/s speed= 394x

It seems that ffmpeg will map 6 channels to 2 channels, but the stereo output file will lose the LEF sound effect.

However, I think it's more reasonable to keep the number of channels unchanged

The test6.wav is downloaded from https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav

Thanks for you reply :-D

@sinkinben
Copy link
Author

sinkinben commented Feb 6, 2024

For more details about 6 channels (aka 5.1 channel) audio file, refer to https://en.wikipedia.org/wiki/5.1_surround_sound

@dbry
Copy link
Owner

dbry commented Feb 7, 2024

I just tried the latest FFmpeg and can verify what you're seeing: FFmpeg converts a 5.1 file to stereo and drops the LFE. This happens whether I try to generate an ADPCM wav file or a stereo PCM wav file. Dropping the LFE sounds like a bug to me, but often the FFmpeg devs will claim that's the intended behavior.

But the takeaway is that IMA ADPCM files can only be mono or stereo, so FFmpeg doesn't really have a choice but to mix down, and your suggestion of keeping the number of channels unchanged is impossible unless you want invalid ADPCM files that no software will play.

@tumagonx
Copy link

It would great if this supported, FMOD (dominant sound engine for games) for example support compressing multichannel (4.0 or 5.1) wav with IMA. Many sound editor including audacity and wavosaur support plain PCM multichannel wav but get stuck if IMA used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants