Page 1 of 1

Continuous sound from 1sec. sample

Posted: Tue Aug 29, 2017 6:48 pm
by SeeLook
Hi,

Is it possible to having a samples of a tone of 1 second long, pragmatically (c++) assemble any duration of this tone?
I mean, i.e. how to loop that audio data:
I already tried to combine and cross-fade last samples with samples at start (10-100ms) but all my attempts have kind of crack during transition.

The question is not about code exactly, but more about approach. How midi sound is produced from some audio data?

Re: Continuous sound from 1sec. sample

Posted: Tue Aug 29, 2017 11:19 pm
by fundamental
What type of sound? (drum/guitar/horn/wildlife/etc)

Have you tried matching zero crossings for when your fading out/fading in?

How are you fading? (linear/log-equal-volume)

Is the goal a droning sound? (you could use fft->phase-randomization->ifft if that's the case)

Re: Continuous sound from 1sec. sample

Posted: Wed Aug 30, 2017 6:25 pm
by SeeLook
Thanks for the answer.

The sound is a single note of instrument with continuous (not fading out) sound: sax, accordion, violin, etc.

I'm fading in/out by increasing/decreasing amplitude of beginning/end of sound, I'm multiplexing every sample by increasing/decreasing factor during in 5ms span time.

My goal is to having samples of each note achieved by instrument with limited duration (1.5) produce any longer and robust sound of that note.
I'm doing that realtime in callback.

Re: Continuous sound from 1sec. sample

Posted: Thu Aug 31, 2017 1:51 am
by Michael Willis
Doing it realtime is going to be tough. I haven't done anything of the sort myself, but I have read tales of woe from Paul Battersby when he was working on looping samples one by one for his excellent Virtual Playing Orchestra.

Re: Continuous sound from 1sec. sample

Posted: Thu Aug 31, 2017 8:19 am
by raboof
One trick I used in a distant past that may help is to 'pingpong' through the sample instead of 'looping' it. Still probably needs some fading and you'll likely still hear the length of the loop, but it should reduce the 'crack'.

Re: Continuous sound from 1sec. sample

Posted: Thu Aug 31, 2017 5:09 pm
by SeeLook
Thanks a lot for clues,

You convinced me to try following:
- find start point at zero-cross before highest peak of note period at about 200ms of a sound (to skip initial part)
- find end point also at zero-cross but at the sound end (90% of duration)
- a) loop between those points
- b) pingpong??? Is that mean to revert directions when end point is achieved?

I can prepare those points when samples are loaded to memory, to have them ready in callback,
and fading in callback by multiplying samples during they are copied to output buffer is light thing. Either JACK in low latency (64 frames) bears it or low end, old mobile device. I had never problem with that.
I believe I can have samples with equal dynamic, but a vibrato of a violin could be a challenge.
I will try and give You feedback.

Re: Continuous sound from 1sec. sample

Posted: Thu Aug 31, 2017 10:24 pm
by ssj71
I've played a lot with this for my infamous stuck plugin. You can view the source at https://github.com/ssj71/infamousPlugin ... ck/stuck.c

I used an autocorrelation method to try to identify a period in the ballpark of 2 and 15 ms. I then layer 2 periods of time with a crossfade. I tried some compression but it didn't seem to imrpove things very much. I was set on keeping in the time domain, but for polyphonic sounds (such as a guitar chord) it still has some beating/loop artifacts. I tried more layers, various crossfacdes etc, but I think you can;t get much better without using some time domain techniques. If I were to do it over again, I'd use a phase vocoder. I've looked a bit at the paulstretch algorithm which works very well for "freezing" audio, I actually planned to try taking just that module and making a stuck 2.

Another lv2 plugin example which does use a phase vocoder IIRC is the https://github.com/romi1502/MrFreeze

I actually haven't tried it yet, it was written for the MOD ecosystem (but should be easily portable). Unfortunately I've heard it still has some artifacts. To be sure this is a difficult problem in the audio world. Not unsolveable though, just needs polish.