Multiply audio samples

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiply audio samples

Michael Koch
Is it possible to multiply audio samples from two sources?
I'd like to downconvert the 15kHz to 25kHz range to the 0 to 10kHz
range. First apply a strong 15kHz highpass filter, then multiply the
signal with a 15kHz sine wave (which produces sum and difference
signals), then apply a 10kHz lowpass filter.

Michael
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
Hi,

On 9/12/18, Michael Koch <[hidden email]> wrote:
> Is it possible to multiply audio samples from two sources?
> I'd like to downconvert the 15kHz to 25kHz range to the 0 to 10kHz
> range. First apply a strong 15kHz highpass filter, then multiply the
> signal with a 15kHz sine wave (which produces sum and difference
> signals), then apply a 10kHz lowpass filter.

There is no yet amultiply audio filter, but I could write it.

Am I correct that for it you need two audio streams as input and one
audio stream as output?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch
Am 12.09.2018 um 09:55 schrieb Paul B Mahol:

> Hi,
>
> On 9/12/18, Michael Koch <[hidden email]> wrote:
>> Is it possible to multiply audio samples from two sources?
>> I'd like to downconvert the 15kHz to 25kHz range to the 0 to 10kHz
>> range. First apply a strong 15kHz highpass filter, then multiply the
>> signal with a 15kHz sine wave (which produces sum and difference
>> signals), then apply a 10kHz lowpass filter.
> There is no yet amultiply audio filter, but I could write it.
>
> Am I correct that for it you need two audio streams as input and one
> audio stream as output?

yes, two inputs and one output. I think it would be best if it works
independant of bit depth. First normalize the input signals to -1...+1
range, then multiply them so that the result is also in the -1...+1
range, then normalize back to 16bit or 24bit range.

Michael

--
**********************************************
   ASTRO ELECTRONIC   Dipl.-Ing. Michael Koch
        Raabestr. 43   37412 Herzberg
           www.astro-electronic.de
   Tel. +49 5521 854265   Fax +49 5521 854266
**********************************************

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
On 9/12/18, Michael Koch <[hidden email]> wrote:

> Am 12.09.2018 um 09:55 schrieb Paul B Mahol:
>> Hi,
>>
>> On 9/12/18, Michael Koch <[hidden email]> wrote:
>>> Is it possible to multiply audio samples from two sources?
>>> I'd like to downconvert the 15kHz to 25kHz range to the 0 to 10kHz
>>> range. First apply a strong 15kHz highpass filter, then multiply the
>>> signal with a 15kHz sine wave (which produces sum and difference
>>> signals), then apply a 10kHz lowpass filter.
>> There is no yet amultiply audio filter, but I could write it.
>>
>> Am I correct that for it you need two audio streams as input and one
>> audio stream as output?
>
> yes, two inputs and one output. I think it would be best if it works
> independant of bit depth. First normalize the input signals to -1...+1
> range, then multiply them so that the result is also in the -1...+1
> range, then normalize back to 16bit or 24bit range.

It will internally work with floating-point numbers only (32bits or 64bits).
Normalization is done with other filters.

Meanwhile you can use sox multiply effect.

Note that sox internally operates with 32bit integers.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
On 9/12/18, Paul B Mahol <[hidden email]> wrote:

> On 9/12/18, Michael Koch <[hidden email]> wrote:
>> Am 12.09.2018 um 09:55 schrieb Paul B Mahol:
>>> Hi,
>>>
>>> On 9/12/18, Michael Koch <[hidden email]> wrote:
>>>> Is it possible to multiply audio samples from two sources?
>>>> I'd like to downconvert the 15kHz to 25kHz range to the 0 to 10kHz
>>>> range. First apply a strong 15kHz highpass filter, then multiply the
>>>> signal with a 15kHz sine wave (which produces sum and difference
>>>> signals), then apply a 10kHz lowpass filter.
>>> There is no yet amultiply audio filter, but I could write it.
>>>
>>> Am I correct that for it you need two audio streams as input and one
>>> audio stream as output?
>>
>> yes, two inputs and one output. I think it would be best if it works
>> independant of bit depth. First normalize the input signals to -1...+1
>> range, then multiply them so that the result is also in the -1...+1
>> range, then normalize back to 16bit or 24bit range.
>
> It will internally work with floating-point numbers only (32bits or
> 64bits).
> Normalization is done with other filters.
>
> Meanwhile you can use sox multiply effect.
>
> Note that sox internally operates with 32bit integers.
>

You can find filter in master branch of FFmpeg repository.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch

>>> yes, two inputs and one output. I think it would be best if it works
>>> independant of bit depth. First normalize the input signals to -1...+1
>>> range, then multiply them so that the result is also in the -1...+1
>>> range, then normalize back to 16bit or 24bit range.
>> It will internally work with floating-point numbers only (32bits or
>> 64bits).
>> Normalization is done with other filters.
>>
>> Meanwhile you can use sox multiply effect.
>>
>> Note that sox internally operates with 32bit integers.
>>
> You can find filter in master branch of FFmpeg repository.

Which other filter can I use to convert the input to -1..+1 interval,
and convert the output back to 16bit or 24bit interval? I saw that the
multiply filter in sox has these normalizations already included.

Thanks,
Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Gyan Doshi
On Sat, Sep 15, 2018 at 12:13 PM Michael Koch <[hidden email]>
wrote:

>
> Which other filter can I use to convert the input to -1..+1 interval,
> and convert the output back to 16bit or 24bit interval? I saw that the
> multiply filter in sox has these normalizations already included.
>

The aformat filter will allow you to convert between integer and floating
point formats. See
http://ffmpeg.org/doxygen/trunk/group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5
for the various formats available.

Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch
Am 15.09.2018 um 09:33 schrieb Gyan:
> On Sat, Sep 15, 2018 at 12:13 PM Michael Koch <[hidden email]>
> wrote:
>
>> Which other filter can I use to convert the input to -1..+1 interval,
>> and convert the output back to 16bit or 24bit interval? I saw that the
>> multiply filter in sox has these normalizations already included.
>>
> The aformat filter will allow you to convert between integer and floating
> point formats.

That's not what I mean.
Let's assume I want to multiply two 16-bit audio samples. The interval
is [-2^15 ... +2^15].
After multiplication  the interval would be [-2^30 ... +2^30], which is
not a usable interval for audio samples.
That means I must either divide the result by 2^15, or I must convert
the inputs to the [-1 ... +1] interval before multiplication, so that
the result is also in the [-1 ... +1] interval, and then multiply by 2^15.
My question is how to make this multipliaction or division by 2^15.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
On 9/15/18, Michael Koch <[hidden email]> wrote:

> Am 15.09.2018 um 09:33 schrieb Gyan:
>> On Sat, Sep 15, 2018 at 12:13 PM Michael Koch
>> <[hidden email]>
>> wrote:
>>
>>> Which other filter can I use to convert the input to -1..+1 interval,
>>> and convert the output back to 16bit or 24bit interval? I saw that the
>>> multiply filter in sox has these normalizations already included.
>>>
>> The aformat filter will allow you to convert between integer and floating
>> point formats.
>
> That's not what I mean.
> Let's assume I want to multiply two 16-bit audio samples. The interval
> is [-2^15 ... +2^15].
> After multiplication  the interval would be [-2^30 ... +2^30], which is
> not a usable interval for audio samples.
> That means I must either divide the result by 2^15, or I must convert
> the inputs to the [-1 ... +1] interval before multiplication, so that
> the result is also in the [-1 ... +1] interval, and then multiply by 2^15.
> My question is how to make this multipliaction or division by 2^15.

Filter inputs will be auto-converted from any non-float formats to
float or double one.

Float/double formats are in [-1 .. +1] interval.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Gyan Doshi
On Sat, Sep 15, 2018 at 2:14 PM Paul B Mahol <[hidden email]> wrote:

> On 9/15/18, Michael Koch <[hidden email]> wrote:
>
> > That's not what I mean.
> > Let's assume I want to multiply two 16-bit audio samples. The interval
> > is [-2^15 ... +2^15].
> > After multiplication  the interval would be [-2^30 ... +2^30], which is
> > not a usable interval for audio samples.
> > That means I must either divide the result by 2^15, or I must convert
> > the inputs to the [-1 ... +1] interval before multiplication, so that
> > the result is also in the [-1 ... +1] interval, and then multiply by
> 2^15.
> > My question is how to make this multipliaction or division by 2^15.
>
> Filter inputs will be auto-converted from any non-float formats to
> float or double one.
>

And aformat=s16p can be added afterwards to get back to [-2^15..2^15]

Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch
In reply to this post by Paul B Mahol
> Filter inputs will be auto-converted from any non-float formats to
> float or double one. Float/double formats are in [-1 .. +1] interval.

Thank you very much for the amultiply filter, it works great!

Here is an example for an ultrasonic converter which downconverts the
15kHz - 25kHz band to the 0 - 10kHz band.

First make an input file for testing. This is a 2 second 19kHz tone
followed by 2 seconds silence:

c://ffmpeg/ffmpeg -f lavfi -i
"sine=frequency=19000:sample_rate=48000:duration=2" -af apad -t 4
ultrasonic.wav

Then use the downconverter:

c://ffmpeg/ffmpeg -i ultrasonic.wav -f lavfi -i
"sine=frequency=15000:sample_rate=48000" -filter_complex
"[0]highpass=f=15000,highpass=f=15000,highpass=f=15000,highpass=f=15000[sound];[1]volume=8[sine];[sound][sine]amultiply[mixed];[mixed]lowpass=f=10000,lowpass=f=10000,lowpass=f=10000,lowpass=f=10000"
out.wav

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
On 9/16/18, Michael Koch <[hidden email]> wrote:

>> Filter inputs will be auto-converted from any non-float formats to
>> float or double one. Float/double formats are in [-1 .. +1] interval.
>
> Thank you very much for the amultiply filter, it works great!
>
> Here is an example for an ultrasonic converter which downconverts the
> 15kHz - 25kHz band to the 0 - 10kHz band.
>
> First make an input file for testing. This is a 2 second 19kHz tone
> followed by 2 seconds silence:
>
> c://ffmpeg/ffmpeg -f lavfi -i
> "sine=frequency=19000:sample_rate=48000:duration=2" -af apad -t 4
> ultrasonic.wav
>
> Then use the downconverter:
>
> c://ffmpeg/ffmpeg -i ultrasonic.wav -f lavfi -i
> "sine=frequency=15000:sample_rate=48000" -filter_complex
> "[0]highpass=f=15000,highpass=f=15000,highpass=f=15000,highpass=f=15000[sound];[1]volume=8[sine];[sound][sine]amultiply[mixed];[mixed]lowpass=f=10000,lowpass=f=10000,lowpass=f=10000,lowpass=f=10000"
> out.wav

Nice, it might be better to use aevalsrc, because it have multichannel output.

For stronger highpass/lowpass you can use aiir filter if you know
correct parameters.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch
Am 16.09.2018 um 22:25 schrieb Paul B Mahol:

> On 9/16/18, Michael Koch <[hidden email]> wrote:
>>> Filter inputs will be auto-converted from any non-float formats to
>>> float or double one. Float/double formats are in [-1 .. +1] interval.
>> Thank you very much for the amultiply filter, it works great!
>>
>> Here is an example for an ultrasonic converter which downconverts the
>> 15kHz - 25kHz band to the 0 - 10kHz band.
>>
>> First make an input file for testing. This is a 2 second 19kHz tone
>> followed by 2 seconds silence:
>>
>> c://ffmpeg/ffmpeg -f lavfi -i
>> "sine=frequency=19000:sample_rate=48000:duration=2" -af apad -t 4
>> ultrasonic.wav
>>
>> Then use the downconverter:
>>
>> c://ffmpeg/ffmpeg -i ultrasonic.wav -f lavfi -i
>> "sine=frequency=15000:sample_rate=48000" -filter_complex
>> "[0]highpass=f=15000,highpass=f=15000,highpass=f=15000,highpass=f=15000[sound];[1]volume=8[sine];[sound][sine]amultiply[mixed];[mixed]lowpass=f=10000,lowpass=f=10000,lowpass=f=10000,lowpass=f=10000"
>> out.wav
> Nice, it might be better to use aevalsrc, because it have multichannel output.

you are right, in my example the 15kHz sine source was only mono, and so
the conversion did only work for one channel. I did change

[1]volume=8[sine]

to

[1]volume=8,aeval=val(0)|val(0)[sine]

and now it works for both channels.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch
In reply to this post by Paul B Mahol

>
>> c://ffmpeg/ffmpeg -i ultrasonic.wav -f lavfi -i
>> "sine=frequency=15000:sample_rate=48000" -filter_complex
>> "[0]highpass=f=15000,highpass=f=15000,highpass=f=15000,highpass=f=15000[sound];[1]volume=8[sine];[sound][sine]amultiply[mixed];[mixed]lowpass=f=10000,lowpass=f=10000,lowpass=f=10000,lowpass=f=10000"
>> out.wav

The ultrasonics converter works fine if used with an audio file, but now
I wanted to convert a video and I always get this error message
"Unsupported channel layout "0 channels" which I don't understand. I
want the audio be converted and the video copied as-is. Here is the
console output:

c://ffmpeg/ffmpeg -i 7Z7A1699.MOV -f lavfi -i
  "sine=frequency=12000:sample_rate=48000" -filter_complex
"[0]highpass=f=12000,h
ighpass=f=12000,highpass=f=12000,highpass=f=12000[sound];[1]volume=8,aeval=val(0
)|val(0)[sine];[sound][sine]amultiply,lowpass=f=10000,lowpass=f=10000,lowpass=f=
10000,lowpass=f=10000" -y out.mp4
ffmpeg version N-91960-g63c69d51c7 Copyright (c) 2000-2018 the FFmpeg
developers

   built with gcc 8.2.1 (GCC) 20180813
   configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libbluray
--enable-lib
freetype --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amr
wb --enable-libopenjpeg --enable-libopus --enable-libshine
--enable-libsnappy --
enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx
--enable-l
ibwavpack --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxml2 --
enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-libvidstab --en
able-libvorbis --enable-libvo-amrwbenc --enable-libmysofa
--enable-libspeex --en
able-libxvid --enable-libaom --enable-libmfx --enable-amf
--enable-ffnvcodec --e
nable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec
--enable-dxva2 --enab
le-avisynth
   libavutil      56. 19.101 / 56. 19.101
   libavcodec     58. 30.100 / 58. 30.100
   libavformat    58. 18.101 / 58. 18.101
   libavdevice    58.  4.103 / 58.  4.103
   libavfilter     7. 31.100 /  7. 31.100
   libswscale      5.  2.100 /  5.  2.100
   libswresample   3.  2.100 /  3.  2.100
   libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '7Z7A1699.MOV':
   Metadata:
     major_brand     : qt
     minor_version   : 538247680
     compatible_brands: qt  CAEP
     com.apple.quicktime.make: Canon
     com.apple.quicktime.model: Canon EOS 5D Mark IV
     com.apple.quicktime.rating.user: 0.000000
     com.apple.quicktime.author: Michael Koch
     creation_time   : 2018-09-14T18:20:37.000000Z
   Duration: 00:00:53.00, start: 0.000000, bitrate: 89479 kb/s
     Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661),
yuvj420p(pc, bt709
), 1920x1080, 87897 kb/s, 25 fps, 25 tbr, 25k tbn, 50k tbc (default)
     Metadata:
       creation_time   : 2018-09-14T18:20:37.000000Z
       timecode        : 00:00:46:17
     Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz,
stereo, s1
6, 1536 kb/s (default)
     Metadata:
       creation_time   : 2018-09-14T18:20:37.000000Z
       timecode        : 00:00:46:17
     Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
     Metadata:
       creation_time   : 2018-09-14T18:20:37.000000Z
       timecode        : 00:00:46:17
Input #1, lavfi, from 'sine=frequency=12000:sample_rate=48000':
   Duration: N/A, start: 0.000000, bitrate: 768 kb/s
     Stream #1:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Stream mapping:
   Stream #0:1 (pcm_s16le) -> highpass (graph 0)
   Stream #1:0 (pcm_s16le) -> volume (graph 0)
   lowpass (graph 0) -> Stream #0:0 (aac)
   Stream #0:0 -> #0:1 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[aac @ 0000000002d6c280] Unsupported channel layout "0 channels"
Error initializing output stream 0:0 -- Error while opening encoder for
output s
tream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or
height
Conversion failed!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Paul B Mahol
On 9/20/18, Michael Koch <[hidden email]> wrote:

>
>>
>>> c://ffmpeg/ffmpeg -i ultrasonic.wav -f lavfi -i
>>> "sine=frequency=15000:sample_rate=48000" -filter_complex
>>> "[0]highpass=f=15000,highpass=f=15000,highpass=f=15000,highpass=f=15000[sound];[1]volume=8[sine];[sound][sine]amultiply[mixed];[mixed]lowpass=f=10000,lowpass=f=10000,lowpass=f=10000,lowpass=f=10000"
>>> out.wav
>
> The ultrasonics converter works fine if used with an audio file, but now
> I wanted to convert a video and I always get this error message
> "Unsupported channel layout "0 channels" which I don't understand. I
> want the audio be converted and the video copied as-is. Here is the
> console output:

add:

aformat=channel_layouts=stereo after aeval filter.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Multiply audio samples

Michael Koch

> add:
>
> aformat=channel_layouts=stereo after aeval filter.

thank you, now it works fine.

Michael
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".