Jump to content


Photo

Make all samples 8 bit-tool


  • Please log in to reply
3 replies to this topic

#1 Kommandotolken

Kommandotolken

    New Member

  • Normal Members
  • Pip
  • 3 posts

Posted 17 June 2017 - 11:44

Hello! I am pseudo coding my first tool which makes all your samples 8 bit. Basically, if you want it to sound lo-fi or maybe sound more like a very old sampler, it could be one way to do it. Anyways, here is m y code. 

local function make_8bitize()
--for renoise.song():instrument(index) do
--renoise.song().instruments[].samples[].sample_buffer.bit_depth
--  -> [read-only, 8]

It is my first one, and I am new to Lua, but I have some programming experience. I need the program to iterate through all the instrument slots and see if there is a sample, if there is, change it to 8 bit. 

Can I have some advice on how to go about doing this? Is there a keyword for the maximum amount of instruments in the project?

for i = 0 and i < renoise.song():instrumet(maximum) do ?



#2 Ledger

Ledger

    Guruh Motha Fakka Knows More About Renoise Than Taktik

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3399 posts
  • Gender:Male

Posted 17 June 2017 - 14:15

Hi Kommandotolken,
 
You can use the Lua Length operator `#` in front of tables to get the number of entries, so:
 

for i = 1, #renoise.song().instruments do

Note: the count would be from 1 and not 0 aswell.
 
 
You would also need to do an internal loop for the list of samples in each instrument, so:
 
 

for i = 1, #renoise.song().instruments do
  for j = 1, #renoise.song():instrument(i).samples do
    --access bit depth
    renoise.song():instrument(i):sample(j).sample_buffer.bit_depth 
  end
end

 
 edit: it looks like the .bit_depth is read only from the docs so it looks like you will need to work with the sample data directly.  A part of the API I`ve not delved into but here are the relevant docs:

--------------------------------------------------------------------------------
-- renoise.SampleBuffer
--------------------------------------------------------------------------------

-------- Constants

renoise.SampleBuffer.CHANNEL_LEFT
renoise.SampleBuffer.CHANNEL_RIGHT
renoise.SampleBuffer.CHANNEL_LEFT_AND_RIGHT


-------- Functions

-- Create new sample data with the given rate, bit-depth, channel and frame
-- count. Will trash existing sample data. Initial buffer is all zero.
-- Will only return false when memory allocation fails (you're running out
-- of memory). All other errors are fired as usual.
renoise.song().instruments[].samples[].sample_buffer:create_sample_data(
  sample_rate, bit_depth, num_channels, num_frames)
    -> [boolean, success]
-- Delete existing sample data.
renoise.song().instruments[].samples[].sample_buffer:delete_sample_data()

-- Read access to samples in a sample data buffer.
renoise.song().instruments[].samples[].sample_buffer:sample_data(
  channel_index, frame_index)
  -> [number -1-1]

-- Write access to samples in a sample data buffer. New samples values must be
-- within [-1, 1] and will be clipped automatically. Sample buffers may be 
-- read-only (see property 'read_only'). Attempts to write on such buffers 
-- will result into errors.
-- IMPORTANT: before modifying buffers, call 'prepare_sample_data_changes'.
-- When you are done, call 'finalize_sample_data_changes' to generate undo/redo
-- data for your changes and update sample overview caches!
renoise.song().instruments[].samples[].sample_buffer:set_sample_data(
  channel_index, frame_index, sample_value)

-- To be called once BEFORE sample data gets manipulated via 'set_sample_data'.
-- This will prepare undo/redo data for the whole sample. See also
-- 'finalize_sample_data_changes'.
renoise.song().instruments[].samples[].sample_buffer:prepare_sample_data_changes()
-- To be called once AFTER the sample data is manipulated via 'set_sample_data'.
-- This will create undo/redo data for the whole sample, and also  update the
-- sample view caches for the sample. The reason this isn't automatically
-- invoked is to avoid performance overhead when changing sample data 'sample by
-- sample'. Don't forget to call this after any data changes, or changes may not
-- be visible in the GUI and can not be un/redone!
renoise.song().instruments[].samples[].sample_buffer:finalize_sample_data_changes()

-- Load sample data from a file. Files can be any audio format Renoise supports.
-- Possible errors are shown to the user, otherwise success is returned.
renoise.song().instruments[].samples[].sample_buffer:load_from(filename)
  -> [boolean, success]
-- Export sample data to a file. Possible errors are shown to the user,
-- otherwise success is returned. Valid export types are 'wav' or 'flac'.
renoise.song().instruments[].samples[].sample_buffer:save_as(filename, format)
  -> [boolean, success]


-------- Properties

-- Has sample data?
renoise.song().instruments[].samples[].sample_buffer.has_sample_data
  -> [read-only, boolean]

-- _NOTE: All following properties are invalid when no sample data is present,
-- 'has_sample_data' returns false:_

-- True, when the sample buffer can only be read, but not be modified. true for
-- sample aliases of sliced samples. To modify such sample buffers, modify the 
-- sliced master sample buffer instead.
renoise.song().instruments[].samples[].sample_buffer.read_only
  -> [read-only, boolean]
  
-- The current sample rate in Hz, like 44100.
renoise.song().instruments[].samples[].sample_buffer.sample_rate
  -> [read-only, number]

-- The current bit depth, like 32, 16, 8.
renoise.song().instruments[].samples[].sample_buffer.bit_depth
  -> [read-only, number]

-- The number of sample channels (1 or 2)
renoise.song().instruments[].samples[].sample_buffer.number_of_channels
  -> [read-only, number]

-- The sample frame count (number of samples per channel)
renoise.song().instruments[].samples[].sample_buffer.number_of_frames
  -> [read-only, number]

-- The first sample displayed in the sample editor view. Set together with
-- DisplayLength to control zooming.
renoise.song().instruments[].samples[].sample_buffer.display_start, _observable
  -> [number >= 1 <= number_of_frames]

-- The number of samples displayed in the sample editor view. Set together with
-- DisplayStart to control zooming.
renoise.song().instruments[].samples[].sample_buffer.display_length, _observable
  -> [number >= 1 <= number_of_frames]

-- The start and end points of the sample editor display.
renoise.song().instruments[].samples[].sample_buffer.display_range[], _observable
  -> [array of two numbers, 1-number_of_frames]

-- The vertical zoom level where 1.0 is fully zoomed out.
renoise.song().instruments[].samples[].sample_buffer.vertical_zoom_factor, _observable
   -> [number, 0.0-1.0]

-- Selection range as visible in the sample editor. always valid. returns the entire
-- buffer when no selection is present in the UI.
renoise.song().instruments[].samples[].sample_buffer.selection_start, _observable
  -> [number >= 1 <= number_of_frames]
renoise.song().instruments[].samples[].sample_buffer.selection_end, _observable
  -> [number >= 1 <= number_of_frames]
renoise.song().instruments[].samples[].sample_buffer.selection_range[], _observable
  -> [array of two numbers, 1-number_of_frames]

-- The selected channel.
renoise.song().instruments[].samples[].sample_buffer.selected_channel, _observable
  -> [enum = CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LEFT_AND_RIGHT]

 
 


Edited by Ledger, 17 June 2017 - 14:21.

--> Lua For Beginners <--
--> Lua for newbies <--

My Scripts On Forum

Top Tip!

 

cpu : Xeon 1231 v3, os : Win 7 64bit, audio: Audient iD4
posts as 4tune @ KvR and some other music related sites


#3 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1502 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 17 June 2017 - 14:16

2)

for instr_index = 1, #renoise.song().instruments do

#table is the same as table.getn(table),

 

or table:getn() if you have created the table by table.create() and thus enabled fancy table methods.

 

1) You can't convert to 8-bit by changing the bit_depth property in sample_buffer, as it is read-only. I'm pretty sure the only way to do it is to replace the old sample with a completely new sample, and populating it with sample data spit out from your very own 8-bit conversion function. Finally delete the old sample :P


Edited by joule, 17 June 2017 - 14:22.


#4 Djeroek

Djeroek

    Probably More God or Borg Than Human Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 6721 posts
  • Gender:Male
  • Location:Borneo

Posted 05 July 2017 - 21:30

I think this tool does what you want using sox;

http://forum.renoise...-dbatchprocess/