Old 03-07-2024, 01:03 PM   #1
b2001
Human being with feelings
 
Join Date: Nov 2006
Location: Washington
Posts: 676
Default Send AudioAccessor buffer to new item/track?

I am able to read the audio data and fft it.

Looking to make changes, ifft and then send results to a new take on a new track.

Is this doable - the sending of the buffer to a new item - and are there any examples that would demonstrate?
b2001 is offline   Reply With Quote
Old 03-07-2024, 02:44 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Not possible.


But you can write this data in binary respecting wav file structure, and import it in project.
X-Raym is offline   Reply With Quote
Old 03-07-2024, 04:39 PM   #3
b2001
Human being with feelings
 
Join Date: Nov 2006
Location: Washington
Posts: 676
Default

Thanks for the response!

so I tried that:

Code:
-------------------------------------------------------------------------------------
-- function
-------------------------------------------------------------------------------------
function WriteWavFile(wav_file, sample_buffer, block_size)
   local number_of_out_channels = 1 
   local writer = reaper.Xen_AudioWriter_Create(wav_file, number_of_out_channels, 44100)
   if (writer ~= nil) then
      local result = reaper.Xen_AudioWriter_Write(writer, block_size, sample_buffer, 1)
      if (result == 0) then 
	     reaper.ShowConsoleMsg("Fail during writing\n") 
		 --break 
	  end
      reaper.Xen_AudioWriter_Destroy(writer) -- file is only finalized when the writer is destroyed
   else
      -- Can fail if file directory path does not exist, no write permissions, disk full...
      reaper.ShowConsoleMsg("Could not create writer\n")
   end
end
based on...

Code:
sample_buffer = reaper.new_array(block_and_overlap_size * item.number_of_channels)
...   sample_buffer.clear()
...   GetSamples(audio, item.sample_rate, item.number_of_channels, start_time_seconds, block_and_overlap_size, sample_buffer) ...
block_size = 2048, overlap = 0, number_of_channels = 1

I am getting a return of 0 - failure - for "reaper.Xen_AudioWriter_Write" and consequently a blank wav file.

Any ideas on what I might be doing wrong?
b2001 is offline   Reply With Quote
Old 03-07-2024, 05:40 PM   #4
b2001
Human being with feelings
 
Join Date: Nov 2006
Location: Washington
Posts: 676
Default

Ok, got it working. The buffer needed a little extra space for indexing…

I only tested for a single blocksize 2048 of 529000 (12 seconds) but i can see it works when i resort the code.

Thanks again!
b2001 is offline   Reply With Quote
Old 03-08-2024, 04:59 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Ah nice use of the Xen function, I forgot about it.


Well done !
X-Raym is offline   Reply With Quote
Old 03-30-2024, 11:03 AM   #6
b2001
Human being with feelings
 
Join Date: Nov 2006
Location: Washington
Posts: 676
Default

Quote:
But you can write this data in binary respecting wav file structure, and import it in project.
Could you elaborate on this? Example?

The xen function does work except, i am of course looping thru audio accessories a block at a time so i get a small wav file or a series of small wav files if i rename them all.

I tried putting the xen create outside the audio accessaries loop and the write inside it - hoping it might append - but got a nasty c++ runtime error which i couldn’t seem to break out of except for shutting down. I am sure this relates to my lack of understanding…

Ultimately, i am looking at using the reascript fft and ifft functions, doing some manipulations in between - to be determined - and writing the results to a wav file to reimport.

Worse come to worse i could just import the series of wav files and glue them, just gets messy with block size of say 1024 or 2048 as item size gets bigger.

Edit —————->

Seems it’s helpful to post questions, usually leads to me figuring it out right after.
While i moved xen create outside the loop, i forgot to move xen destroy outside the loop. Works great now!

Last edited by b2001; 03-30-2024 at 12:19 PM.
b2001 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.