repo
string
commit
string
message
string
diff
string
mattetti/googlecharts
6217011c86bb668a807c80cf6abf3fe693417526
separate labels and legends for pies
diff --git a/lib/gchart.rb b/lib/gchart.rb index ac9e2e6..c2f4d95 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,687 +1,687 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :labels, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors, :usemap attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 #URI.escape( string ).gsub("%7C", "|") # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} #string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " usemap=\"#{usemap}\"" if usemap image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend - if type.to_s =~ /pie|pie_3d|meter/ + if type.to_s =~ /meter/ @labels = legend return set_labels end if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if labels.is_a?(Array) "chl=#{@labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@labels}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 || step && max && step > max # this is a full series max = axis_range.compact.max step = nil end [index, (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@labels' set_labels unless labels.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index cd16ab7..3dc72fe 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,655 +1,655 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ describe "The Gchart class" do it "should show supported_types on error" do Gchart.supported_types.should match(/line/) end it "should return supported types" do Gchart.types.include?('line').should be_true end end describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => 26, :axis_with_labels => 'y').should include('chxr=0,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end it "should be able to have missing data points with text encoding" do Gchart.line(:data => [10, 5.2, nil, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,_,45,78') end it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end it "should be able to have multiple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end def labeled_line(options = {}) Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge(options)) end it "should display ranges properly" do @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] labeled_line(:axis_labels => [((1..24).to_a << 1)]). should include('chxr=0,85,672') end def labeled_bar(options = {}) Gchart.bar({:data => @data, :axis_with_labels => 'x,y', :axis_labels => [(1..12).to_a], :encoding => "text" }.merge(options)) end it "should force the y range properly" do @data = [1,1,1,1,1,1,1,1,6,2,1,1] labeled_bar( :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,0|1,0,16') labeled_bar( :max_value => 16, :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,16|1,0,16') # nil means ignore axis labeled_bar( :axis_range => [nil,[0,16]] ).should include('chxr=1,0,16') # empty array means take defaults labeled_bar( :max_value => 16, :axis_range => [[],[0,16]] ).should include('chxr=0,0,16|1,0,16') labeled_bar( :axis_range => [[],[0,16]] ).should include('chxr=0,0|1,0,16') Gchart.line( :data => [0,20, 40, 60, 140, 230, 60], :axis_with_labels => 'y').should include("chxr=0,0,230") end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [((1..24).to_a << 1)], :max_value => 700) url.should include('chxr=0,85,700') end it 'should generate different labels and legend' do - Gchart.line(:legend => %w(1 2 3), :labels=>%w(one two three)).should(include('chdl=1|2|3')) - Gchart.line(:legend => %w(1 2 3), :labels=>%w(one two three)).should(include('chl=one|two|three')) + Gchart.pie(:legend => %w(1 2 3), :labels=>%w(one two three)).should(include('chdl=1|2|3') && include('chl=one|two|three')) end - + end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do msg = "sexy is not a supported chart format. Please use one of the following: #{Gchart.supported_types}." lambda{Gchart.sexy}.should raise_error(NoMethodError) end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do @options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do Gchart.line(:range_markers => @options.merge(:orientation => 'v')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'V')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'R')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'vertical')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do Gchart.line(:range_markers => @options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'h')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do Gchart.line(:range_markers => @options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end - it "should be able to set labels by using the legend or labesl accessor" do - Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") - Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") - Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) - end - end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end + it "should be able to set labels by using the legend or labesl accessor" do + Gchart.meter(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") + Gchart.meter(:title => @title, :labels => @legend, :data => @data).should == Gchart.meter(:title => @title, :legend => @legend, :data => @data) + end + + + end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
fdbbff60843e06b81860ee2e0cbc37367ed34124
bumped the version
diff --git a/VERSION b/VERSION index afaf360..fdd3be6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.6.2 diff --git a/lib/gchart/version.rb b/lib/gchart/version.rb index 524cab3..f2cbe72 100644 --- a/lib/gchart/version.rb +++ b/lib/gchart/version.rb @@ -1,9 +1,9 @@ module GchartInfo #:nodoc: module VERSION #:nodoc: MAJOR = 1 - MINOR = 5 - TINY = 4 + MINOR = 6 + TINY = 2 STRING = [MAJOR, MINOR, TINY].join('.') end end
mattetti/googlecharts
7e8cc2457c6812fbac800e3610ea01963ca56453
Version bump to 1.0.0
diff --git a/VERSION b/VERSION index bd52db8..afaf360 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.0 \ No newline at end of file +1.0.0 \ No newline at end of file
mattetti/googlecharts
48a27f59628547d5357fccd4c14df478b234b1ca
Version bump to 0.0.0
diff --git a/VERSION b/VERSION index 9dbb0c0..bd52db8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.0 \ No newline at end of file +0.0.0 \ No newline at end of file
mattetti/googlecharts
55265f0844d0f7f0ed97f04dda39dfe80de52908
Version bump to 1.7.0
diff --git a/VERSION b/VERSION index 9c6d629..9dbb0c0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +1.7.0 \ No newline at end of file
mattetti/googlecharts
09633d67b831e88ce27aed7cb2c015e5dc0c159a
added test
diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index ee2f4e2..cd16ab7 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,650 +1,655 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ describe "The Gchart class" do it "should show supported_types on error" do Gchart.supported_types.should match(/line/) end it "should return supported types" do Gchart.types.include?('line').should be_true end end describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => 26, :axis_with_labels => 'y').should include('chxr=0,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end it "should be able to have missing data points with text encoding" do Gchart.line(:data => [10, 5.2, nil, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,_,45,78') end it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end it "should be able to have multiple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end def labeled_line(options = {}) Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge(options)) end it "should display ranges properly" do @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] labeled_line(:axis_labels => [((1..24).to_a << 1)]). should include('chxr=0,85,672') end def labeled_bar(options = {}) Gchart.bar({:data => @data, :axis_with_labels => 'x,y', :axis_labels => [(1..12).to_a], :encoding => "text" }.merge(options)) end it "should force the y range properly" do @data = [1,1,1,1,1,1,1,1,6,2,1,1] labeled_bar( :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,0|1,0,16') labeled_bar( :max_value => 16, :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,16|1,0,16') # nil means ignore axis labeled_bar( :axis_range => [nil,[0,16]] ).should include('chxr=1,0,16') # empty array means take defaults labeled_bar( :max_value => 16, :axis_range => [[],[0,16]] ).should include('chxr=0,0,16|1,0,16') labeled_bar( :axis_range => [[],[0,16]] ).should include('chxr=0,0|1,0,16') Gchart.line( :data => [0,20, 40, 60, 140, 230, 60], :axis_with_labels => 'y').should include("chxr=0,0,230") end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [((1..24).to_a << 1)], :max_value => 700) url.should include('chxr=0,85,700') end - + + it 'should generate different labels and legend' do + Gchart.line(:legend => %w(1 2 3), :labels=>%w(one two three)).should(include('chdl=1|2|3')) + Gchart.line(:legend => %w(1 2 3), :labels=>%w(one two three)).should(include('chl=one|two|three')) + end + end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do msg = "sexy is not a supported chart format. Please use one of the following: #{Gchart.supported_types}." lambda{Gchart.sexy}.should raise_error(NoMethodError) end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do @options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do Gchart.line(:range_markers => @options.merge(:orientation => 'v')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'V')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'R')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'vertical')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do Gchart.line(:range_markers => @options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'h')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do Gchart.line(:range_markers => @options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end it "should be able to set labels by using the legend or labesl accessor" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) end end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
3ab82e7865163bec3e2442c289876f2a9dd6abd3
restored labels based on official docs
diff --git a/googlecharts.gemspec b/googlecharts.gemspec index 051910b..d940f2e 100644 --- a/googlecharts.gemspec +++ b/googlecharts.gemspec @@ -1,76 +1,76 @@ # Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{googlecharts} - s.version = "1.6.1" + s.version = "1.6.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Matt Aimonetti"] s.date = %q{2011-02-06} s.description = %q{Generate charts using Google API & Ruby} s.email = %q{[email protected]} s.extra_rdoc_files = [ "README", "README.markdown", "README.txt" ] s.files = [ "History.txt", "License.txt", "Manifest.txt", "README", "README.markdown", "README.txt", "Rakefile", "VERSION", "config/hoe.rb", "config/requirements.rb", "lib/gchart.rb", "lib/gchart/aliases.rb", "lib/gchart/theme.rb", "lib/gchart/version.rb", "lib/googlecharts.rb", "lib/themes.yml", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/fixtures/another_test_theme.yml", "spec/fixtures/test_theme.yml", "spec/gchart_spec.rb", "spec/spec_helper.rb", "spec/theme_spec.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/rspec.rake", "tasks/website.rake", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.rhtml" ] s.homepage = %q{http://googlecharts.rubyforge.org/} s.require_paths = ["lib"] s.rubygems_version = %q{1.3.7} s.summary = %q{Generate charts using Google API & Ruby} s.test_files = [ "spec/gchart_spec.rb", "spec/spec_helper.rb", "spec/theme_spec.rb" ] if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then else end else end end diff --git a/lib/gchart.rb b/lib/gchart.rb index 171b3ef..ac9e2e6 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,683 +1,687 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end - attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, + attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :labels, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors, :usemap attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 #URI.escape( string ).gsub("%7C", "|") # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} #string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " usemap=\"#{usemap}\"" if usemap image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend - return set_labels if type.to_s =~ /pie|pie_3d|meter/ - + if type.to_s =~ /pie|pie_3d|meter/ + @labels = legend + return set_labels + end if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels - if legend.is_a?(Array) - "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" + if labels.is_a?(Array) + "chl=#{@labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else - "chl=#{@legend}" + "chl=#{@labels}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 || step && max && step > max # this is a full series max = axis_range.compact.max step = nil end [index, (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? + when '@labels' + set_labels unless labels.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/lib/gchart/aliases.rb b/lib/gchart/aliases.rb index 2ca75fb..48d5627 100644 --- a/lib/gchart/aliases.rb +++ b/lib/gchart/aliases.rb @@ -1,16 +1,15 @@ class Gchart alias_method :background=, :bg= alias_method :chart_bg=, :graph_bg= alias_method :chart_color=, :graph_bg= alias_method :chart_background=, :graph_bg= alias_method :bar_color=, :bar_colors= alias_method :line_colors=, :bar_colors= alias_method :line_color=, :bar_colors= alias_method :slice_colors=, :bar_colors= - alias_method :labels=, :legend= alias_method :horizontal?, :horizontal alias_method :grouped?, :grouped alias_method :curved?, :curved end
mattetti/googlecharts
87574fe3d1ad1238bd7f250a6fa7906187f64f95
Regenerate gemspec for version 1.6.1
diff --git a/googlecharts.gemspec b/googlecharts.gemspec new file mode 100644 index 0000000..051910b --- /dev/null +++ b/googlecharts.gemspec @@ -0,0 +1,76 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{googlecharts} + s.version = "1.6.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Matt Aimonetti"] + s.date = %q{2011-02-06} + s.description = %q{Generate charts using Google API & Ruby} + s.email = %q{[email protected]} + s.extra_rdoc_files = [ + "README", + "README.markdown", + "README.txt" + ] + s.files = [ + "History.txt", + "License.txt", + "Manifest.txt", + "README", + "README.markdown", + "README.txt", + "Rakefile", + "VERSION", + "config/hoe.rb", + "config/requirements.rb", + "lib/gchart.rb", + "lib/gchart/aliases.rb", + "lib/gchart/theme.rb", + "lib/gchart/version.rb", + "lib/googlecharts.rb", + "lib/themes.yml", + "script/destroy", + "script/generate", + "script/txt2html", + "setup.rb", + "spec/fixtures/another_test_theme.yml", + "spec/fixtures/test_theme.yml", + "spec/gchart_spec.rb", + "spec/spec_helper.rb", + "spec/theme_spec.rb", + "tasks/deployment.rake", + "tasks/environment.rake", + "tasks/rspec.rake", + "tasks/website.rake", + "website/index.html", + "website/index.txt", + "website/javascripts/rounded_corners_lite.inc.js", + "website/stylesheets/screen.css", + "website/template.rhtml" + ] + s.homepage = %q{http://googlecharts.rubyforge.org/} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.7} + s.summary = %q{Generate charts using Google API & Ruby} + s.test_files = [ + "spec/gchart_spec.rb", + "spec/spec_helper.rb", + "spec/theme_spec.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + else + end + else + end +end +
mattetti/googlecharts
df1cd847d071ccb6ada204211f947c1a88b1c752
Revert "Version bump to 0.0.0"
diff --git a/VERSION b/VERSION index bd52db8..9c6d629 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.0 \ No newline at end of file +1.6.1
mattetti/googlecharts
be4d34570d95fd347393c93e2e7443d3bc4af6a6
Version bump to 0.0.0
diff --git a/VERSION b/VERSION index 9c6d629..bd52db8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +0.0.0 \ No newline at end of file
mattetti/googlecharts
2df36211ae21cb43c9f82e647c97f2ce2e98465f
fixed axis label bugs, updated the specs and added some more documentation
diff --git a/README.markdown b/README.markdown index 5e9d00a..399ea4a 100644 --- a/README.markdown +++ b/README.markdown @@ -1,296 +1,325 @@ The goal of this Gem is to make the creation of Google Charts a simple and easy task. - + + require 'googlecharts' Gchart.line( :size => '200x300', :title => "example title", :bg => 'efefef', :legend => ['first data set label', 'second data set label'], :data => [10, 30, 120, 45, 72]) Check out the [full documentation over there](http://googlecharts.rubyforge.org/) This gem is fully tested using Rspec, check the rspec folder for more examples. See at the bottom of this file who reported using this gem. Chart Type ------------- This gem supports the following types of charts: * line, * line_xy * sparkline * scatter * bar * venn * pie * pie_3d * google meter Googlecharts also supports graphical themes and you can easily load your own. To create a chart, simply require Gchart and call any of the existing type: require 'gchart' Gchart.pie Chart Title ------------- To add a title to a chart pass the title to your chart: Gchart.line(:title => 'Sexy Charts!') You can also specify the color and/or size Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20') Colors ------------- Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example: * FF0000 = red * 00FF00 = green * 0000FF = blue * 000000 = black * FFFFFF = white You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example: * 0000FFFF = solid blue * 0000FF00 = transparent blue If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00' Some charts have more options than other, make sure to refer to the documentation. Background options: ------------- If you don't set the background option, your graph will be transparent. * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill - solid - gradient - stripes By default, if you set a background color, the fill will be solid: Gchart.bar(:bg => 'efefef') However you can specify another fill type such as: Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}) In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows: Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90}) For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}) The same way you set the background color, you can also set the graph background: Gchart.line(:graph_bg => 'cccccc') or both Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart') Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}) You can customize the amount of stripes, colors and width by changing the color value. Themes -------- Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from [Gruff](http://github.com/topfunky/gruff/tree/master) Gchart.line( :theme => :keynote, :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]], :title => 'keynote' ) * keynote ![keynote](http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000) * thirty7signals ![37signals](http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF) * pastel ![pastel](http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) * greyscale ![greyscale](http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml Load your theme(s): Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") And use the standard method signature to use your own theme: Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale') Legend & Labels ------------- You probably will want to use a legend or labels for your graph. Gchart.line(:legend => 'legend label') or Gchart.line(:legend => ['legend label 1', 'legend label 2']) Will do the trick. You can also use the labels alias (makes more sense when using the pie charts) chart = Gchart.pie(:labels => ['label 1', 'label 2']) Multiple axis labels ------------- Multiple axis labels are available for line charts, bar charts and scatter plots. * x = bottom x-axis * t = top x-axis * y = left y-axis * r = right y-axis Gchart.line(:axis_with_label => 'x,y,r,t') To add labels on these axis: Gchart.line(:axis_with_label => 'x,y,r,t', :axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']) +Note that each array entry could also be an array but represent the +labels for the corresponding axis. + +A question which comes back often is how do I only display the y axis +label? Solution: + + Gchart.line( + :data => [0,20, 40, 60, 140, 230, 60], + :axis_with_labels => 'y') + +Custom axis ranges +--------------- + +If you want to display a custom range for an axis, you need to set the +range as described in the Google charts documentation: min, max, step: + + Gchart.line( :data => [17, 17, 11, 8, 2], + :axis_with_labels => ['x', 'y'], + :axis_labels => [['J', 'F', 'M', 'A', 'M']], + :axis_range => [nil, [2,17,5]]) + + +In this case, the custom axis range is only defined for y (second +entry) with a minimum value of 2, max 17 and a step of 5. + +This is also valid if you want to set a x axis and automatically define +the y labels. + Data options ------------- Data are passed using an array or a nested array. Gchart.bar(:data => [1,2,4,67,100,41,234]) Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]]) By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value. Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300) Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto') or if you want to use the real values from your dataset: Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false) You can also define a different encoding to add more granularity: Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text') Pies: ------------- you have 2 type of pies: - Gchart.pie() the standard 2D pie _ Gchart.pie_3d() the fancy 3D pie To set labels, you can use one of these two options: @legend = ['Matt_fu', 'Rob_fu'] Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200') Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200') Bars: ------------- A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash. The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order: Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12 Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25 The hash lets you set these values directly, with the Google default values set for any options you don't include: Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19}) Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12}) Radar: ------------- In a Radar graph, the x-axis is circular. The points can be connected by straight lines or curved lines. Gchart.radar(:data => @data, :curved => true) Sparklines: ------------- A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default. Google-o-meter ------------- A Google-o-meter has a few restrictions. It may only use a solid filled background and it may only have one label. try yourself ------------- Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]], :title => 'SD Ruby Fu level', :legend => ['matt','patrick'], :bg => {:color => '76A4FB', :type => 'gradient'}, :bar_colors => 'ff0000,00ff00') "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00" Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan']) http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan People reported using this gem: --------------------- ![github](http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png) * [http://github.com](http://github.com) ![stafftool.com](http://stafftool.com/images/masthead_screen.gif) * [http://stafftool.com/](http://stafftool.com/) Takeo (contributor) ![graffletopia.com](http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg) * [graffleropia.com](http://graffletopia.com) Mokolabs (contributor) ![gumgum](http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg) * [http://gumgum.com](http://gumgum.com) Mattetti (Author) ![http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg] * [http://feedflix.com/](http://feedflix.com/) [lifehacker article](http://lifehacker.com/395610/feedflix-creates-detailed-charts-from-your-netflix-use) * [California State University, Chico](http://www.csuchico.edu/) diff --git a/lib/gchart.rb b/lib/gchart.rb index da98b7c..171b3ef 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,686 +1,683 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors, :usemap attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 - URI.escape( string ) + #URI.escape( string ).gsub("%7C", "|") # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 - # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} - # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} + string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} + #string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " usemap=\"#{usemap}\"" if usemap image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end - "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) - # in the case of a line graph, the first axis range should 1 - index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range - if axis_range.size > 3 or step && max && step > max # this is a full series - max = axis_range.last + if axis_range.size > 3 || step && max && step > max # this is a full series + max = axis_range.compact.max step = nil end - [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') + [index, (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index c9711d3..ee2f4e2 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,646 +1,650 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ describe "The Gchart class" do it "should show supported_types on error" do Gchart.supported_types.should match(/line/) end it "should return supported types" do Gchart.types.include?('line').should be_true end end describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') - Gchart.line(:data => [0, 26], :max_value => 26).should include('chxr=1,0,26') + Gchart.line(:data => [0, 26], :max_value => 26, :axis_with_labels => 'y').should include('chxr=0,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end it "should be able to have missing data points with text encoding" do Gchart.line(:data => [10, 5.2, nil, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,_,45,78') end it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end - it "should be able to have muliple set of data with text encoding" do + it "should be able to have multiple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end def labeled_line(options = {}) Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge(options)) end it "should display ranges properly" do @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] labeled_line(:axis_labels => [((1..24).to_a << 1)]). - should include('chxr=1,85,593') + should include('chxr=0,85,672') end def labeled_bar(options = {}) Gchart.bar({:data => @data, :axis_with_labels => 'x,y', :axis_labels => [(1..12).to_a], :encoding => "text" }.merge(options)) end it "should force the y range properly" do @data = [1,1,1,1,1,1,1,1,6,2,1,1] labeled_bar( :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,0|1,0,16') labeled_bar( :max_value => 16, :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,16|1,0,16') # nil means ignore axis labeled_bar( :axis_range => [nil,[0,16]] ).should include('chxr=1,0,16') # empty array means take defaults labeled_bar( :max_value => 16, :axis_range => [[],[0,16]] ).should include('chxr=0,0,16|1,0,16') labeled_bar( :axis_range => [[],[0,16]] ).should include('chxr=0,0|1,0,16') + + Gchart.line( + :data => [0,20, 40, 60, 140, 230, 60], + :axis_with_labels => 'y').should include("chxr=0,0,230") end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [((1..24).to_a << 1)], :max_value => 700) - url.should include('chxr=1,85,700') + url.should include('chxr=0,85,700') end end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do msg = "sexy is not a supported chart format. Please use one of the following: #{Gchart.supported_types}." lambda{Gchart.sexy}.should raise_error(NoMethodError) end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do @options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do Gchart.line(:range_markers => @options.merge(:orientation => 'v')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'V')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'R')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'vertical')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do Gchart.line(:range_markers => @options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'h')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do Gchart.line(:range_markers => @options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end it "should be able to set labels by using the legend or labesl accessor" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) end end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
f577da91e200c0fe7aa3c6d535fb2fc74f39d758
Added usemap option to img tag
diff --git a/lib/gchart.rb b/lib/gchart.rb index c922a81..da98b7c 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,685 +1,686 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, - :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors + :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors, :usemap attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 URI.escape( string ) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title + image += " usemap=\"#{usemap}\"" if usemap image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end
mattetti/googlecharts
b52e2f35cf986e6984c7d54a168caeed2d61fab5
Added alias "slice_colors"
diff --git a/lib/gchart/aliases.rb b/lib/gchart/aliases.rb index 0669a30..2ca75fb 100644 --- a/lib/gchart/aliases.rb +++ b/lib/gchart/aliases.rb @@ -1,15 +1,16 @@ class Gchart alias_method :background=, :bg= alias_method :chart_bg=, :graph_bg= alias_method :chart_color=, :graph_bg= alias_method :chart_background=, :graph_bg= alias_method :bar_color=, :bar_colors= alias_method :line_colors=, :bar_colors= alias_method :line_color=, :bar_colors= + alias_method :slice_colors=, :bar_colors= alias_method :labels=, :legend= alias_method :horizontal?, :horizontal alias_method :grouped?, :grouped alias_method :curved?, :curved end
mattetti/googlecharts
bbad68d74dce1eba6b75cdd7539d8bc2322fe023
Remove redundant #size method
diff --git a/lib/gchart.rb b/lib/gchart.rb index 3160634..c922a81 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,619 +1,615 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end - def size=(size='300x200') - @width, @height = size.split("x").map { |dimension| dimension.to_i } - end - def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 URI.escape( string ) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds
mattetti/googlecharts
b4d0aa1bdc72f8689167a0d8b16511270233e4a4
Fix Gchart.supported_types to work right
diff --git a/lib/gchart.rb b/lib/gchart.rb index 5995818..3160634 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,608 +1,607 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) - raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." + raise NoMethodError, "#{m} is not a supported chart format. Please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end - def self.supported_types - self.class.types.join(' ') + self.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 URI.escape( string ) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index f7ebb89..c9711d3 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,636 +1,646 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ +describe "The Gchart class" do + it "should show supported_types on error" do + Gchart.supported_types.should match(/line/) + end + + it "should return supported types" do + Gchart.types.include?('line').should be_true + end +end + describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => 26).should include('chxr=1,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end it "should be able to have missing data points with text encoding" do Gchart.line(:data => [10, 5.2, nil, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,_,45,78') end it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end it "should be able to have muliple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end def labeled_line(options = {}) Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge(options)) end it "should display ranges properly" do @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] labeled_line(:axis_labels => [((1..24).to_a << 1)]). should include('chxr=1,85,593') end def labeled_bar(options = {}) Gchart.bar({:data => @data, :axis_with_labels => 'x,y', :axis_labels => [(1..12).to_a], :encoding => "text" }.merge(options)) end it "should force the y range properly" do @data = [1,1,1,1,1,1,1,1,6,2,1,1] labeled_bar( :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,0|1,0,16') labeled_bar( :max_value => 16, :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,16|1,0,16') # nil means ignore axis labeled_bar( :axis_range => [nil,[0,16]] ).should include('chxr=1,0,16') # empty array means take defaults labeled_bar( :max_value => 16, :axis_range => [[],[0,16]] ).should include('chxr=0,0,16|1,0,16') labeled_bar( :axis_range => [[],[0,16]] ).should include('chxr=0,0|1,0,16') end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [((1..24).to_a << 1)], :max_value => 700) url.should include('chxr=1,85,700') end end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do - lambda{Gchart.sexy}.should raise_error - # msg => "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}." + msg = "sexy is not a supported chart format. Please use one of the following: #{Gchart.supported_types}." + lambda{Gchart.sexy}.should raise_error(NoMethodError) end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do @options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do Gchart.line(:range_markers => @options.merge(:orientation => 'v')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'V')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'R')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'vertical')).include?('chm=R').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do Gchart.line(:range_markers => @options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'h')).include?('chm=r').should be_true Gchart.line(:range_markers => @options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do Gchart.line(:range_markers => @options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end it "should be able to set labels by using the legend or labesl accessor" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) end end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
e9c7cee7f50e842391f428690e481fe09af68db2
Removed unused 'count' variable
diff --git a/lib/gchart.rb b/lib/gchart.rb index 7111703..5995818 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,691 +1,690 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.class.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See http://github.com/mattetti/googlecharts/issues#issue/27 URI.escape( string ) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end - count = labels_arr.length "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end
mattetti/googlecharts
f623f28c6cfb5ade2e46101f4b0d80486ea649ee
Use URI.escape in jstize
diff --git a/lib/gchart.rb b/lib/gchart.rb index df41c8b..7111703 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,689 +1,691 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.class.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) + # See http://github.com/mattetti/googlecharts/issues#issue/27 + URI.escape( string ) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 - string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} + # string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end count = labels_arr.length "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end
mattetti/googlecharts
aa2d58aeaa26b6cb6a15dd487d1b202ff1d37399
doc patch for #issue/2
diff --git a/README.markdown b/README.markdown index 7ef926d..5e9d00a 100644 --- a/README.markdown +++ b/README.markdown @@ -1,295 +1,296 @@ The goal of this Gem is to make the creation of Google Charts a simple and easy task. Gchart.line( :size => '200x300', :title => "example title", :bg => 'efefef', :legend => ['first data set label', 'second data set label'], :data => [10, 30, 120, 45, 72]) Check out the [full documentation over there](http://googlecharts.rubyforge.org/) This gem is fully tested using Rspec, check the rspec folder for more examples. See at the bottom of this file who reported using this gem. Chart Type ------------- This gem supports the following types of charts: * line, * line_xy * sparkline * scatter * bar * venn * pie * pie_3d * google meter Googlecharts also supports graphical themes and you can easily load your own. To create a chart, simply require Gchart and call any of the existing type: require 'gchart' Gchart.pie Chart Title ------------- To add a title to a chart pass the title to your chart: Gchart.line(:title => 'Sexy Charts!') You can also specify the color and/or size Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20') Colors ------------- Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example: * FF0000 = red * 00FF00 = green * 0000FF = blue * 000000 = black * FFFFFF = white You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example: * 0000FFFF = solid blue * 0000FF00 = transparent blue If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00' Some charts have more options than other, make sure to refer to the documentation. Background options: ------------- If you don't set the background option, your graph will be transparent. * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill - solid - gradient - stripes By default, if you set a background color, the fill will be solid: Gchart.bar(:bg => 'efefef') However you can specify another fill type such as: Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}) In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows: Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90}) For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}) The same way you set the background color, you can also set the graph background: Gchart.line(:graph_bg => 'cccccc') or both Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart') Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}) You can customize the amount of stripes, colors and width by changing the color value. Themes -------- Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from [Gruff](http://github.com/topfunky/gruff/tree/master) Gchart.line( :theme => :keynote, :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]], :title => 'keynote' ) * keynote ![keynote](http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000) * thirty7signals ![37signals](http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF) * pastel ![pastel](http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) * greyscale ![greyscale](http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml Load your theme(s): Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") And use the standard method signature to use your own theme: Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale') Legend & Labels ------------- You probably will want to use a legend or labels for your graph. Gchart.line(:legend => 'legend label') or Gchart.line(:legend => ['legend label 1', 'legend label 2']) Will do the trick. You can also use the labels alias (makes more sense when using the pie charts) chart = Gchart.pie(:labels => ['label 1', 'label 2']) Multiple axis labels ------------- Multiple axis labels are available for line charts, bar charts and scatter plots. * x = bottom x-axis * t = top x-axis * y = left y-axis * r = right y-axis - Gchart.line(:label_axis => 'x,y,r') + Gchart.line(:axis_with_label => 'x,y,r,t') To add labels on these axis: - Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']) + Gchart.line(:axis_with_label => 'x,y,r,t', + :axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']) Data options ------------- Data are passed using an array or a nested array. Gchart.bar(:data => [1,2,4,67,100,41,234]) Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]]) By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value. Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300) Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto') or if you want to use the real values from your dataset: Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false) You can also define a different encoding to add more granularity: Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text') Pies: ------------- you have 2 type of pies: - Gchart.pie() the standard 2D pie _ Gchart.pie_3d() the fancy 3D pie To set labels, you can use one of these two options: @legend = ['Matt_fu', 'Rob_fu'] Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200') Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200') Bars: ------------- A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash. The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order: Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12 Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25 The hash lets you set these values directly, with the Google default values set for any options you don't include: Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19}) Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12}) Radar: ------------- In a Radar graph, the x-axis is circular. The points can be connected by straight lines or curved lines. Gchart.radar(:data => @data, :curved => true) Sparklines: ------------- A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default. Google-o-meter ------------- A Google-o-meter has a few restrictions. It may only use a solid filled background and it may only have one label. try yourself ------------- Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]], :title => 'SD Ruby Fu level', :legend => ['matt','patrick'], :bg => {:color => '76A4FB', :type => 'gradient'}, :bar_colors => 'ff0000,00ff00') "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00" Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan']) http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan People reported using this gem: --------------------- ![github](http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png) * [http://github.com](http://github.com) ![stafftool.com](http://stafftool.com/images/masthead_screen.gif) * [http://stafftool.com/](http://stafftool.com/) Takeo (contributor) ![graffletopia.com](http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg) * [graffleropia.com](http://graffletopia.com) Mokolabs (contributor) ![gumgum](http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg) * [http://gumgum.com](http://gumgum.com) Mattetti (Author) ![http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg] * [http://feedflix.com/](http://feedflix.com/) [lifehacker article](http://lifehacker.com/395610/feedflix-creates-detailed-charts-from-your-netflix-use) * [California State University, Chico](http://www.csuchico.edu/)
mattetti/googlecharts
0eaa3379e66f74ba909ab9b5831cfd6ad615e703
change from spec to rspec
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f1ca062..aa8a18e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ begin - require 'spec' + require 'rspec' rescue LoadError require 'rubygems' gem 'rspec' - require 'spec' -end \ No newline at end of file + require 'rspec' +end diff --git a/tasks/rspec.rake b/tasks/rspec.rake index b256d1c..81f562a 100644 --- a/tasks/rspec.rake +++ b/tasks/rspec.rake @@ -1,21 +1,22 @@ begin - require 'spec' + require 'rspec' rescue LoadError require 'rubygems' - require 'spec' + require 'rspec' end + begin - require 'spec/rake/spectask' + require 'rspec/core/rake_task' + + desc "Run the specs under spec/models" + RSpec::Core::RakeTask.new do |t| + # t.rspec_opts = ['--options', "spec/spec.opts"] + end rescue LoadError puts <<-EOS To use rspec for testing you must install rspec gem: gem install rspec EOS exit(0) end -desc "Run the specs under spec/models" -Spec::Rake::SpecTask.new do |t| - t.spec_opts = ['--options', "spec/spec.opts"] - t.spec_files = FileList['spec/*_spec.rb'] -end
mattetti/googlecharts
6c557e07eb934548e1a2ae81a8382d4cd435b593
Version bump to 1.6.1
diff --git a/VERSION b/VERSION index dc1e644..9c6d629 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.0 +1.6.1
mattetti/googlecharts
e51a17f00cd80742b04ddee8cc9f0d86707415d2
support missing (nil) data values for text encoding
diff --git a/lib/gchart.rb b/lib/gchart.rb index 3f7f4d3..df41c8b 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -107,583 +107,583 @@ class Gchart end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end count = labels_arr.length "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval set = @calculated_axis_range ? datasets : axis_range || datasets return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| next nil if axis_range.nil? # ignore this axis min, max, step = axis_range if axis_range.size > 3 or step && max && step > max # this is a full series max = axis_range.last step = nil end [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") - "t" + number_visible + ":" + datasets.map{ |ds| ds.join(',') }.join('|') + "&chds=" + chds + "t" + number_visible + ":" + datasets.map{ |ds| ds.map{|e|e||'_'}.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index 7bb1bca..f7ebb89 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,632 +1,636 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => 26).should include('chxr=1,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end + it "should be able to have missing data points with text encoding" do + Gchart.line(:data => [10, 5.2, nil, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,_,45,78') + end + it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end it "should be able to have muliple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end def labeled_line(options = {}) - Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge options) + Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge(options)) end it "should display ranges properly" do @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] - labeled_line(:axis_labels => [(1.upto(24).to_a << 1)]). + labeled_line(:axis_labels => [((1..24).to_a << 1)]). should include('chxr=1,85,593') end def labeled_bar(options = {}) Gchart.bar({:data => @data, :axis_with_labels => 'x,y', - :axis_labels => [1.upto(12).to_a], + :axis_labels => [(1..12).to_a], :encoding => "text" }.merge(options)) end it "should force the y range properly" do @data = [1,1,1,1,1,1,1,1,6,2,1,1] labeled_bar( :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,0|1,0,16') labeled_bar( :max_value => 16, :axis_range => [[0,0],[0,16]] ).should include('chxr=0,0,16|1,0,16') # nil means ignore axis labeled_bar( :axis_range => [nil,[0,16]] ).should include('chxr=1,0,16') # empty array means take defaults labeled_bar( :max_value => 16, :axis_range => [[],[0,16]] ).should include('chxr=0,0,16|1,0,16') labeled_bar( :axis_range => [[],[0,16]] ).should include('chxr=0,0|1,0,16') end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] - url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)], :max_value => 700) + url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [((1..24).to_a << 1)], :max_value => 700) url.should include('chxr=1,85,700') end end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do lambda{Gchart.sexy}.should raise_error # msg => "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}." end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do - options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} + @options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do - Gchart.line(:range_markers => options.merge(:orientation => 'v')).include?('chm=R').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'V')).include?('chm=R').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'R')).include?('chm=R').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'vertical')).include?('chm=R').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'v')).include?('chm=R').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'V')).include?('chm=R').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'R')).include?('chm=R').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'vertical')).include?('chm=R').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do - Gchart.line(:range_markers => options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'h')).include?('chm=r').should be_true - Gchart.line(:range_markers => options.merge(:orientation => 'etc')).include?('chm=r').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'h')).include?('chm=r').should be_true + Gchart.line(:range_markers => @options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do - Gchart.line(:range_markers => options).include?('chm=r').should be_true + Gchart.line(:range_markers => @options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end it "should be able to set labels by using the legend or labesl accessor" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) end end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
dce6be668c409b8a71ad871d5f30accb5d5c2bc0
Version bump to 1.6.0
diff --git a/VERSION b/VERSION index 94fe62c..dc1e644 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.4 +1.6.0
mattetti/googlecharts
7ae5dbd6c6e843d55819c5ca6aec5fc457fb1d32
add radar example
diff --git a/README.markdown b/README.markdown index 1361a29..7ef926d 100644 --- a/README.markdown +++ b/README.markdown @@ -1,290 +1,295 @@ The goal of this Gem is to make the creation of Google Charts a simple and easy task. Gchart.line( :size => '200x300', :title => "example title", :bg => 'efefef', :legend => ['first data set label', 'second data set label'], :data => [10, 30, 120, 45, 72]) Check out the [full documentation over there](http://googlecharts.rubyforge.org/) This gem is fully tested using Rspec, check the rspec folder for more examples. See at the bottom of this file who reported using this gem. Chart Type ------------- This gem supports the following types of charts: * line, * line_xy * sparkline * scatter * bar * venn * pie * pie_3d * google meter Googlecharts also supports graphical themes and you can easily load your own. To create a chart, simply require Gchart and call any of the existing type: require 'gchart' Gchart.pie Chart Title ------------- To add a title to a chart pass the title to your chart: Gchart.line(:title => 'Sexy Charts!') You can also specify the color and/or size Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20') Colors ------------- Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example: * FF0000 = red * 00FF00 = green * 0000FF = blue * 000000 = black * FFFFFF = white You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example: * 0000FFFF = solid blue * 0000FF00 = transparent blue If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00' Some charts have more options than other, make sure to refer to the documentation. Background options: ------------- If you don't set the background option, your graph will be transparent. * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill - solid - gradient - stripes By default, if you set a background color, the fill will be solid: Gchart.bar(:bg => 'efefef') However you can specify another fill type such as: Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}) In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows: Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90}) For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}) The same way you set the background color, you can also set the graph background: Gchart.line(:graph_bg => 'cccccc') or both Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart') Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}) You can customize the amount of stripes, colors and width by changing the color value. Themes -------- Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from [Gruff](http://github.com/topfunky/gruff/tree/master) Gchart.line( :theme => :keynote, :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]], :title => 'keynote' ) * keynote ![keynote](http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000) * thirty7signals ![37signals](http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF) * pastel ![pastel](http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) * greyscale ![greyscale](http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml Load your theme(s): Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") And use the standard method signature to use your own theme: Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale') Legend & Labels ------------- You probably will want to use a legend or labels for your graph. Gchart.line(:legend => 'legend label') or Gchart.line(:legend => ['legend label 1', 'legend label 2']) Will do the trick. You can also use the labels alias (makes more sense when using the pie charts) chart = Gchart.pie(:labels => ['label 1', 'label 2']) Multiple axis labels ------------- Multiple axis labels are available for line charts, bar charts and scatter plots. * x = bottom x-axis * t = top x-axis * y = left y-axis * r = right y-axis Gchart.line(:label_axis => 'x,y,r') To add labels on these axis: Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']) Data options ------------- Data are passed using an array or a nested array. Gchart.bar(:data => [1,2,4,67,100,41,234]) Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]]) By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value. Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300) Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto') or if you want to use the real values from your dataset: Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false) You can also define a different encoding to add more granularity: Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended') Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text') Pies: ------------- you have 2 type of pies: - Gchart.pie() the standard 2D pie _ Gchart.pie_3d() the fancy 3D pie To set labels, you can use one of these two options: @legend = ['Matt_fu', 'Rob_fu'] Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200') Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200') Bars: ------------- A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash. The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order: Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12 Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6 Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25 The hash lets you set these values directly, with the Google default values set for any options you don't include: Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19}) Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12}) +Radar: +------------- + In a Radar graph, the x-axis is circular. The points can be connected by straight lines or curved lines. + Gchart.radar(:data => @data, :curved => true) + Sparklines: ------------- A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default. Google-o-meter ------------- A Google-o-meter has a few restrictions. It may only use a solid filled background and it may only have one label. try yourself ------------- Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]], :title => 'SD Ruby Fu level', :legend => ['matt','patrick'], :bg => {:color => '76A4FB', :type => 'gradient'}, :bar_colors => 'ff0000,00ff00') "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00" Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan']) http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan People reported using this gem: --------------------- ![github](http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png) * [http://github.com](http://github.com) ![stafftool.com](http://stafftool.com/images/masthead_screen.gif) * [http://stafftool.com/](http://stafftool.com/) Takeo (contributor) ![graffletopia.com](http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg) * [graffleropia.com](http://graffletopia.com) Mokolabs (contributor) ![gumgum](http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg) * [http://gumgum.com](http://gumgum.com) Mattetti (Author) ![http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg] * [http://feedflix.com/](http://feedflix.com/) [lifehacker article](http://lifehacker.com/395610/feedflix-creates-detailed-charts-from-your-netflix-use) -* [California State University, Chico](http://www.csuchico.edu/) \ No newline at end of file +* [California State University, Chico](http://www.csuchico.edu/)
mattetti/googlecharts
f24f3f3fa1e7ecd6a0f51af4b10d051f52c4288f
axis labeling arrrays edge cases
diff --git a/lib/gchart.rb b/lib/gchart.rb index 223e7ec..3f7f4d3 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,688 +1,689 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.class.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end count = labels_arr.length "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval - if @calculated_axis_range - set = datasets - else - set = axis_range || datasets - end + set = @calculated_axis_range ? datasets : axis_range || datasets + + return unless set && set.respond_to?(:each) && set.find {|o| o}.respond_to?(:each) + # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 - if set && set.respond_to?(:each) && set.first.respond_to?(:each) - 'chxr=' + set.enum_for(:each_with_index).map do |range, index| - [(index + index_increase), (min_value || range.first), (max_value || range.last)].compact.join(',') - end.join("|") - else - nil - end + 'chxr=' + set.enum_for(:each_with_index).map do |axis_range, index| + next nil if axis_range.nil? # ignore this axis + min, max, step = axis_range + if axis_range.size > 3 or step && max && step > max # this is a full series + max = axis_range.last + step = nil + end + [(index + index_increase), (min_value || min || 0), (max_value || max), step].compact.join(',') + end.compact.join("|") end def set_geographical_area "chtm=#{geographical_area}" end def set_type 'cht=' + case type.to_s when 'line' then "lc" when 'line_xy' then "lxy" when 'pie_3d' then "p3" when 'pie' then "p" when 'venn' then "v" when 'scatter' then "s" when 'sparkline' then "ls" when 'meter' then "gom" when 'map' then "t" when 'radar' "r" + (curved? ? 's' : '') when 'bar' "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type when 'solid' then 's' when 'gradient' then 'lg' when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index 194e840..7bb1bca 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -1,607 +1,632 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/gchart' Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") # Time to add your specs! # http://rspec.rubyforge.org/ describe "generating a default Gchart" do before(:each) do @chart = Gchart.line end it "should include the Google URL" do @chart.include?("http://chart.apis.google.com/chart?").should be_true end it "should have a default size" do @chart.should include('chs=300x200') end it "should be able to have a custom size" do Gchart.line(:size => '400x600').include?('chs=400x600').should be_true Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true end it "should have query parameters in predictable order" do Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) end it "should have a type" do @chart.include?('cht=lc').should be_true end it 'should use theme defaults if theme is set' do Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') if RUBY_VERSION.to_f < 1.9 Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) else Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) end end it "should use the simple encoding by default with auto max value" do # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 Gchart.line(:data => [0, 26]).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => 26).should include('chxr=1,0,26') end it "should support simple encoding with and without max_value" do Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') end it "should support the extended encoding and encode properly" do Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true Gchart.line(:encoding => 'extended', :max_value => false, :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true end it "should auto set the max value for extended encoding" do Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') # Extended encoding max value is '..' Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true end it "should be able to have data with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') end it "should handle max and min values with text encoding" do Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') end it "should automatically handle negative values with proper max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') end it "should handle negative values with manual max/min limits when using text encoding" do Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true end it "should set the proper axis values when using text encoding and negative values" do Gchart.bar( :data => [[-10], [100]], :encoding => 'text', :horizontal => true, :min_value => -20, :max_value => 100, :axis_with_labels => 'x', :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") end it "should be able to have muliple set of data with text encoding" do Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true end it "should be able to receive a custom param" do Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true end it "should be able to set label axis" do Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true end it "should be able to have axis labels" do Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true end + def labeled_line(options = {}) + Gchart.line({:data => @data, :axis_with_labels => 'x,y'}.merge options) + end + it "should display ranges properly" do - data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] - url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)]) - url.should include('chxr=1,85,593') + @data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] + labeled_line(:axis_labels => [(1.upto(24).to_a << 1)]). + should include('chxr=1,85,593') end - it "should force the y range properly" do - url = Gchart.bar(:data => [1,1,1,1,1,1,1,1,6,2,1,1], + def labeled_bar(options = {}) + Gchart.bar({:data => @data, :axis_with_labels => 'x,y', - :min_value => 0, - :max_value => 16, :axis_labels => [1.upto(12).to_a], - :axis_range => [[0,0],[0,16]], :encoding => "text" - ) - url.should include('chxr=0,0,16|1,0,16') + }.merge(options)) + end + + it "should force the y range properly" do + @data = [1,1,1,1,1,1,1,1,6,2,1,1] + labeled_bar( + :axis_range => [[0,0],[0,16]] + ).should include('chxr=0,0,0|1,0,16') + labeled_bar( + :max_value => 16, + :axis_range => [[0,0],[0,16]] + ).should include('chxr=0,0,16|1,0,16') + + # nil means ignore axis + labeled_bar( + :axis_range => [nil,[0,16]] + ).should include('chxr=1,0,16') + + # empty array means take defaults + labeled_bar( + :max_value => 16, + :axis_range => [[],[0,16]] + ).should include('chxr=0,0,16|1,0,16') + labeled_bar( + :axis_range => [[],[0,16]] + ).should include('chxr=0,0|1,0,16') end it "should take in consideration the max value when creating a range" do data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)], :max_value => 700) url.should include('chxr=1,85,700') end end describe "generating different type of charts" do it "should be able to generate a line chart" do Gchart.line.should be_an_instance_of(String) Gchart.line.include?('cht=lc').should be_true end it "should be able to generate a sparkline chart" do Gchart.sparkline.should be_an_instance_of(String) Gchart.sparkline.include?('cht=ls').should be_true end it "should be able to generate a line xy chart" do Gchart.line_xy.should be_an_instance_of(String) Gchart.line_xy.include?('cht=lxy').should be_true end it "should be able to generate a scatter chart" do Gchart.scatter.should be_an_instance_of(String) Gchart.scatter.include?('cht=s').should be_true end it "should be able to generate a bar chart" do Gchart.bar.should be_an_instance_of(String) Gchart.bar.include?('cht=bvs').should be_true end it "should be able to generate a Venn diagram" do Gchart.venn.should be_an_instance_of(String) Gchart.venn.include?('cht=v').should be_true end it "should be able to generate a Pie Chart" do Gchart.pie.should be_an_instance_of(String) Gchart.pie.include?('cht=p').should be_true end it "should be able to generate a Google-O-Meter" do Gchart.meter.should be_an_instance_of(String) Gchart.meter.include?('cht=gom').should be_true end it "should be able to generate a map chart" do Gchart.map.should be_an_instance_of(String) Gchart.map.include?('cht=t').should be_true end it "should not support other types" do lambda{Gchart.sexy}.should raise_error # msg => "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}." end end describe "range markers" do it "should be able to generate given a hash of range-marker options" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true end it "should be able to generate given an array of range-marker hash options" do Gchart.line(:range_markers => [ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, {:start_position => 0, :stop_position => 0.6, :color => '666666'}, {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true end it "should allow a :overlaid? to be set" do Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true end describe "when setting the orientation option" do before(:each) do options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} end it "to vertical (R) if given a valid option" do Gchart.line(:range_markers => options.merge(:orientation => 'v')).include?('chm=R').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'V')).include?('chm=R').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'R')).include?('chm=R').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'vertical')).include?('chm=R').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true end it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do Gchart.line(:range_markers => options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'h')).include?('chm=r').should be_true Gchart.line(:range_markers => options.merge(:orientation => 'etc')).include?('chm=r').should be_true end it "if left blank defaults to horizontal (r)" do Gchart.line(:range_markers => options).include?('chm=r').should be_true end end end describe "a bar graph" do it "should have a default vertical orientation" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to have a different orientation" do Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true end it "should be set to be stacked by default" do Gchart.bar.include?('cht=bvs').should be_true end it "should be able to stacked or grouped" do Gchart.bar(:stacked => true).include?('cht=bvs').should be_true Gchart.bar(:stacked => false).include?('cht=bvg').should be_true Gchart.bar(:grouped => true).include?('cht=bvg').should be_true Gchart.bar(:grouped => false).include?('cht=bvs').should be_true end it "should be able to have different bar colors" do Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true # alias Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true end it "should be able to have different bar colors when using an array of colors" do Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true end it 'should be able to accept a string of width and spacing options' do Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true end it 'should be able to accept a single fixnum width and spacing option to set the bar width' do Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true end it 'should be able to accept an array of width and spacing options' do Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true end describe "with a hash of width and spacing options" do before(:each) do @default_width = 23 @default_spacing = 4 @default_group_spacing = 8 end it 'should be able to have a custom bar width' do Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true end it 'should be able to have custom spacing' do Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true end it 'should be able to have custom group spacing' do Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true end end end describe "a line chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @chart = Gchart.line(:title => @title, :legend => @legend) end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should escape text values in url" do title = 'Chart & Title' legend = ['first data & set label', 'n data set label'] chart = Gchart.line(:title => title, :legend => legend) chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.line(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") end it "should be able to set a graph fill" do Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end it "should be able to render a graph where all the data values are 0" do Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") end end describe "a sparkline chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) end it "should create a sparkline" do @chart.include?('cht=ls').should be_true end it 'should be able have a chart title' do @chart.include?("chtt=Chart+Title").should be_true end it "should be able to a custom color and size title" do Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true end it "should be able to have multiple legends" do @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true end it "should be able to have one legend" do chart = Gchart.sparkline(:legend => 'legend label') chart.include?("chdl=legend+label").should be_true end it "should be able to set the background fill" do Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true end it "should be able to set a graph fill" do Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true end it "should be able to set both a graph and a background fill" do Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true if RUBY_VERSION.to_f < 1.9 Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true else Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true end end it "should be able to have different line colors" do Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true end end describe "a 3d pie chart" do before(:each) do @title = 'Chart Title' @legend = ['first data set label', 'n data set label'] @jstized_legend = Gchart.jstize(@legend.join('|')) @data = [12,8,40,15,5] @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) end it "should create a pie" do @chart.include?('cht=p').should be_true end it "should be able to be in 3d" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true end it "should be able to set labels by using the legend or labesl accessor" do Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) end end describe "a google-o-meter" do before(:each) do @data = [70] @legend = ['arrow points here'] @jstized_legend = Gchart.jstize(@legend.join('|')) @chart = Gchart.meter(:data => @data) end it "should create a meter" do @chart.include?('cht=gom').should be_true end it "should be able to set a solid background fill" do Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true end end describe "a map chart" do before(:each) do @data = [0,100,50,32] @geographical_area = 'usa' @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] @country_codes = ['MT', 'WY', "ID", 'SD'] @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', :geographical_area => @geographical_area, :map_colors => @map_colors, :country_codes => @country_codes) end it "should create a map" do @chart.include?('cht=t').should be_true end it "should set the geographical area" do @chart.include?('chtm=usa').should be_true end it "should set the map colors" do @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true end it "should set the country/state codes" do @chart.include?('chld=MTWYIDSD').should be_true end it "should set the chart data" do @chart.include?('chd=t:0,100,50,32').should be_true end end describe 'exporting a chart' do it "should be available in the url format by default" do Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) end it "should be available as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using img_tag alias" do Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom dimensions" do Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) end it "should be available as an image tag using custom alt text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) end it "should be available as an image tag using custom title text" do Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) end it "should be available as an image tag using custom css id selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should be available as an image tag using custom css class selector" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) end it "should use ampersands to separate key/value pairs in URLs by default" do Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } end it "should escape ampersands in URLs when used as an image tag" do Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } end it "should be available as a file" do File.delete('chart.png') if File.exist?('chart.png') Gchart.line(:data => [0, 26], :format => 'file') File.exist?('chart.png').should be_true File.delete('chart.png') if File.exist?('chart.png') end it "should be available as a file using a custom file name" do File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') File.exist?('custom_file_name.png').should be_true File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') end it "should work even with multiple attrs" do File.delete('foo.png') if File.exist?('foo.png') Gchart.line(:size => '400x200', :data => [1,2,3,4,5], # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], :axis_with_labels => 'x,r', :format => "file", :filename => "foo.png" ) File.exist?('foo.png').should be_true File.delete('foo.png') if File.exist?('foo.png') end end
mattetti/googlecharts
3dccca9edb847977a698fca69c2fc92813c5f473
add radius chart with curved option
diff --git a/lib/gchart.rb b/lib/gchart.rb index 1e62fde..223e7ec 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -1,697 +1,688 @@ $:.unshift File.dirname(__FILE__) require 'gchart/version' require 'gchart/theme' require "net/http" require "uri" require "cgi" require 'enumerator' class Gchart include GchartInfo def self.url "http://chart.apis.google.com/chart?" end def self.types - @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map'] + @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar'] end def self.simple_chars @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a end def self.chars @chars ||= simple_chars + ['-', '.'] end def self.ext_pairs @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten end def self.default_filename 'chart.png' end - attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, + attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines attr_accessor :min_value, :max_value types.each do |type| instance_eval <<-DYNCLASSMETH def #{type}(options = {}) # Start with theme defaults if a theme is set theme = options[:theme] options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options # # Extract the format and optional filename, then clean the hash format = options[:format] || 'url' options[:filename] ||= default_filename options.delete(:format) #update map_colors to become bar_colors options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) chart = new(options.merge!({:type => "#{type}"})) chart.send(format) end DYNCLASSMETH end def self.version VERSION::STRING end def self.method_missing(m, options={}) raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." end def initialize(options={}) @type = options[:type] || 'line' @data = [] @width = 300 @height = 200 + @curved = false @horizontal = false @grouped = false @encoding = 'simple' # @max_value = 'auto' # @min_value defaults to nil meaning zero @filename = options[:filename] # Sets the alt tag when chart is exported as image tag @alt = 'Google Chart' # Sets the CSS id selector when chart is exported as image tag @id = false # Sets the CSS class selector when chart is exported as image tag @klass = options[:class] || false # set the options value if definable options.each do |attribute, value| send("#{attribute}=", value) if self.respond_to?("#{attribute}=") end end def self.supported_types self.class.types.join(' ') end # Defines the Graph size using the following format: # width X height def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size=(size='300x200') @width, @height = size.split("x").map { |dimension| dimension.to_i } end def size "#{width}x#{height}" end def dimensions # TODO: maybe others? [:line_xy, :scatter].include?(type) ? 2 : 1 end # Sets the orientation of a bar graph def orientation=(orientation='h') if orientation == 'h' || orientation == 'horizontal' self.horizontal = true elsif orientation == 'v' || orientation == 'vertical' self.horizontal = false end end # Sets the bar graph presentation (stacked or grouped) def stacked=(option=true) @grouped = option ? false : true end def bg=(options) if options.is_a?(String) @bg_color = options elsif options.is_a?(Hash) @bg_color = options[:color] @bg_type = options[:type] @bg_angle = options[:angle] end end def graph_bg=(options) if options.is_a?(String) @chart_color = options elsif options.is_a?(Hash) @chart_color = options[:color] @chart_type = options[:type] @chart_angle = options[:angle] end end def max_value=(max_v) if max_v =~ /false/ @max_value = false else @max_value = max_v end end def min_value=(min_v) if min_v =~ /false/ @min_value = false else @min_value = min_v end end # returns the full data range as an array # it also sets the data range if not defined def full_data_range(ds) return if max_value == false ds.each_with_index do |mds, mds_index| mds[:min_value] ||= min_value mds[:max_value] ||= max_value if mds_index == 0 && type.to_s == 'bar' # TODO: unless you specify a zero line (using chp or chds), # the min_value of a bar chart is always 0. #mds[:min_value] ||= mds[:data].first.to_a.compact.min mds[:min_value] ||= 0 end if (mds_index == 0 && type.to_s == 'bar' && !grouped && mds[:data].first.is_a?(Array)) totals = [] mds[:data].each do |l| l.each_with_index do |v, index| next if v.nil? totals[index] ||= 0 totals[index] += v end end mds[:max_value] ||= totals.compact.max else all = mds[:data].flatten.compact # default min value should be 0 unless set to auto if mds[:min_value] == 'auto' mds[:min_value] = all.min else min = all.min mds[:min_value] ||= (min && min < 0 ? min : 0) end mds[:max_value] ||= all.max end end unless axis_range @calculated_axis_range = true @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} if dimensions == 1 && (type.to_s != 'bar' || horizontal) tmp = axis_range.fetch(0, []) @axis_range[0] = axis_range.fetch(1, []) @axis_range[1] = tmp end end # return [min, max] unless (min.nil? || max.nil?) # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value # # if min_value.nil? # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 # @min = (min_ds_value < 0) ? min_ds_value : 0 # else # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value # end # @axis_range = [[min,max]] end def dataset if @dataset @dataset else @dataset = convert_dataset(data || []) full_data_range(@dataset) # unless axis_range @dataset end end # Sets of data to handle multiple sets def datasets datasets = [] dataset.each do |d| if d[:data].first.is_a?(Array) datasets += d[:data] else datasets << d[:data] end end datasets end def self.jstize(string) # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} end # load all the custom aliases require 'gchart/aliases' # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) def fetch url = URI.parse(self.class.url) req = Net::HTTP::Post.new(url.path) req.body = query_builder req.content_type = 'application/x-www-form-urlencoded' Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body end # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) def write io_or_file = filename || self.class.default_filename return io_or_file.write(fetch) if io_or_file.respond_to?(:write) open(io_or_file, "wb+") { |io| io.write(fetch) } end # Format def image_tag image = "<img" image += " id=\"#{id}\"" if id image += " class=\"#{klass}\"" if klass image += " src=\"#{url_builder(:html)}\"" image += " width=\"#{width}\"" image += " height=\"#{height}\"" image += " alt=\"#{alt}\"" image += " title=\"#{title}\"" if title image += " />" end alias_method :img_tag, :image_tag def url url_builder end def file write end # def jstize(string) self.class.jstize(string) end private # The title size cannot be set without specifying a color. # A dark key will be used for the title color if no color is specified def set_title title_params = "chtt=#{title}" unless (title_color.nil? && title_size.nil? ) title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') end title_params end def set_size "chs=#{size}" end def set_data data = send("#{@encoding}_encoding") "chd=#{data}" end def set_colors @bg_type = fill_type(bg_type) || 's' if bg_color @chart_type = fill_type(chart_type) || 's' if chart_color "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') end # set bar, line colors def set_bar_colors @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) "chco=#{bar_colors}" end def set_country_codes @country_codes = country_codes.join() if country_codes.is_a?(Array) "chld=#{country_codes}" end # set bar spacing # chbh= # <bar width in pixels>, # <optional space between bars in a group>, # <optional space between groups> def set_bar_width_and_spacing width_and_spacing_values = case bar_width_and_spacing when String bar_width_and_spacing when Array bar_width_and_spacing.join(',') when Hash width = bar_width_and_spacing[:width] || 23 spacing = bar_width_and_spacing[:spacing] || 4 group_spacing = bar_width_and_spacing[:group_spacing] || 8 [width,spacing,group_spacing].join(',') else bar_width_and_spacing.to_s end "chbh=#{width_and_spacing_values}" end def set_range_markers markers = case range_markers when Hash set_range_marker(range_markers) when Array range_markers.collect{|marker| set_range_marker(marker)}.join('|') end "chm=#{markers}" end def set_range_marker(options) orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" end def fill_for(type=nil, color='', angle=nil) unless type.nil? case type when 'lg' angle ||= 0 color = "#{color},0,ffffff,1" if color.split(',').size == 1 "#{type},#{angle},#{color}" when 'ls' angle ||= 90 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 "#{type},#{angle},#{color}" else "#{type},#{color}" end end end # A chart can have one or many legends. # Gchart.line(:legend => 'label') # or # Gchart.line(:legend => ['first label', 'last label']) def set_legend return set_labels if type.to_s =~ /pie|pie_3d|meter/ if legend.is_a?(Array) "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chdl=#{legend}" end end def set_line_thickness "chls=#{thickness}" end def set_line_markers "chm=#{new_markers}" end def set_grid_lines "chg=#{grid_lines}" end def set_labels if legend.is_a?(Array) "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "chl=#{@legend}" end end def set_axis_with_labels @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) "chxt=#{axis_with_labels}" end def set_axis_labels if axis_labels.is_a?(Array) if RUBY_VERSION.to_f < 1.9 labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} else labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} end elsif axis_labels.is_a?(Hash) labels_arr = axis_labels.to_a end labels_arr.map! do |index,labels| if labels.is_a?(Array) "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" else "#{index}:|#{labels}" end end count = labels_arr.length "chxl=#{labels_arr.join('|')}" end # http://code.google.com/apis/chart/labels.html#axis_range # Specify a range for axis labels def set_axis_range # a passed axis_range should look like: # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] # in the second example, 4 is the interval if @calculated_axis_range set = datasets else set = axis_range || datasets end # in the case of a line graph, the first axis range should 1 index_increase = type.to_s == 'line' ? 1 : 0 if set && set.respond_to?(:each) && set.first.respond_to?(:each) 'chxr=' + set.enum_for(:each_with_index).map do |range, index| [(index + index_increase), (min_value || range.first), (max_value || range.last)].compact.join(',') end.join("|") else nil end end def set_geographical_area "chtm=#{geographical_area}" end def set_type - case type.to_s - when 'line' - "cht=lc" - when 'line_xy' - "cht=lxy" + 'cht=' + case type.to_s + when 'line' then "lc" + when 'line_xy' then "lxy" + when 'pie_3d' then "p3" + when 'pie' then "p" + when 'venn' then "v" + when 'scatter' then "s" + when 'sparkline' then "ls" + when 'meter' then "gom" + when 'map' then "t" + when 'radar' + "r" + (curved? ? 's' : '') when 'bar' - "cht=b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") - when 'pie_3d' - "cht=p3" - when 'pie' - "cht=p" - when 'venn' - "cht=v" - when 'scatter' - "cht=s" - when 'sparkline' - "cht=ls" - when 'meter' - "cht=gom" - when 'map' - "cht=t" + "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") end end def fill_type(type) case type - when 'solid' - 's' - when 'gradient' - 'lg' - when 'stripes' - 'ls' + when 'solid' then 's' + when 'gradient' then 'lg' + when 'stripes' then 'ls' end end def number_visible n = 0 dataset.each do |mds| return n.to_s if mds[:invisible] == true if mds[:data].first.is_a?(Array) n += mds[:data].length else n += 1 end end "" end # Turns input into an array of axis hashes, dependent on the chart type def convert_dataset(ds) if dimensions == 2 # valid inputs include: # an array of >=2 arrays, or an array of >=2 hashes ds = ds.map do |d| d.is_a?(Hash) ? d : {:data => d} end elsif dimensions == 1 # valid inputs include: # a hash, an array of data, an array of >=1 array, or an array of >=1 hash if ds.is_a?(Hash) ds = [ds] elsif not ds.first.is_a?(Hash) ds = [{:data => ds}] end end ds end # just an alias def axis_set dataset end def convert_to_simple_value(number) if number.nil? "_" else value = self.class.simple_chars[number.to_i] value.nil? ? "_" : value end end def convert_to_extended_value(number) if number.nil? '__' else value = self.class.ext_pairs[number.to_i] value.nil? ? "__" : value end end def encode_scaled_dataset(chars, nil_char) dsets = [] dataset.each do |ds| if max_value != false range = ds[:max_value] - ds[:min_value] range = 1 if range == 0 end unless ds[:data].first.is_a?(Array) ldatasets = [ds[:data]] else ldatasets = ds[:data] end ldatasets.each do |l| dsets << l.map do |number| if number.nil? nil_char else unless range.nil? || range.zero? number = chars.size * (number - ds[:min_value]) / range.to_f number = [number, chars.size - 1].min end chars[number.to_i] end end.join end end dsets.join(',') end # http://code.google.com/apis/chart/#simple # Simple encoding has a resolution of 62 different values. # Allowing five pixels per data point, this is sufficient for line and bar charts up # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. def simple_encoding "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') end # http://code.google.com/apis/chart/#text # Text encoding with data scaling lets you specify arbitrary positive or # negative floating point numbers, in combination with a scaling parameter # that lets you specify a custom range for your chart. This chart is useful # when you don't want to worry about limiting your data to a specific range, # or do the calculations to scale your data down or up to fit nicely inside # a chart. # # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). # # This encoding is not available for maps. # def text_encoding chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") "t" + number_visible + ":" + datasets.map{ |ds| ds.join(',') }.join('|') + "&chds=" + chds end # http://code.google.com/apis/chart/#extended # Extended encoding has a resolution of 4,096 different values # and is best used for large charts where a large data range is required. def extended_encoding "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') end def url_builder(options="") self.class.url + query_builder(options) end def query_builder(options="") query_params = instance_variables.sort.map do |var| case var.to_s when '@data' set_data unless data == [] # Set the graph size when '@width' set_size unless width.nil? || height.nil? when '@type' set_type when '@title' set_title unless title.nil? when '@legend' set_legend unless legend.nil? when '@thickness' set_line_thickness when '@new_markers' set_line_markers when '@bg_color' set_colors when '@chart_color' set_colors if bg_color.nil? when '@bar_colors' set_bar_colors when '@bar_width_and_spacing' set_bar_width_and_spacing when '@axis_with_labels' set_axis_with_labels when '@axis_labels' set_axis_labels when '@range_markers' set_range_markers when '@grid_lines' set_grid_lines when '@geographical_area' set_geographical_area when '@country_codes' set_country_codes when '@custom' custom end end.compact query_params << set_axis_range # Use ampersand as default delimiter unless options == :html delimiter = '&' # Escape ampersand for html image tags else delimiter = '&amp;' end jstize(query_params.join(delimiter)) end end diff --git a/lib/gchart/aliases.rb b/lib/gchart/aliases.rb index f7071fd..0669a30 100644 --- a/lib/gchart/aliases.rb +++ b/lib/gchart/aliases.rb @@ -1,14 +1,15 @@ class Gchart alias_method :background=, :bg= alias_method :chart_bg=, :graph_bg= alias_method :chart_color=, :graph_bg= alias_method :chart_background=, :graph_bg= alias_method :bar_color=, :bar_colors= alias_method :line_colors=, :bar_colors= alias_method :line_color=, :bar_colors= alias_method :labels=, :legend= alias_method :horizontal?, :horizontal alias_method :grouped?, :grouped + alias_method :curved?, :curved -end \ No newline at end of file +end
mattetti/googlecharts
75b8f097adbc3c2e87e01d64f272ecdc663d79e1
Replace hard-coded class name with reflection
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7a1d91 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +log/* +.manifest +pkg \ No newline at end of file diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..7ce5afc --- /dev/null +++ b/History.txt @@ -0,0 +1,48 @@ +== 1.3.6 +* support nil values. The Google Charts API specifies that a single underscore (_) can be used to omit a value from a line chart with 'simple' data encoding, and a double underscore (__) can do the same for a chart with 'extended' data encoding. (Matt Moyer) +* allow a label to appear on a google-o-meter via the :legend option. (hallettj) + +== 1.3.5 +* added code to properly escape image tag URLs (mokolabs) +* added themes support + 4 default themes (keynote, thirty7signals, pastel, greyscale) chart.line(:theme=>:keynote) (jakehow) + +== 1.3.4 +* updated documentation and cleaned it up (mokolabs) +* added support for custom class, id and alt tags when using the image_tag format (i.e Gchart.line(:data => [0, 26], :format => 'image_tag')) (mokolabs) + +== 1.3.2 - 1.3.3 +* changes required by github + +== 1.3.1 +* added width and spacing options + +== 1.3.0 +* added support for google-o-meter +* fixed a bug when the max value of a data set was 0 + +== 1.2.0 +* added support for sparklines + +== 1.1.0 +* fixed another bug fix related to the uri escaping required to download the file properly. + +== 1.0.0 +* fixed the (URI::InvalidURIError) issue + +== 0.2.0 +* added export options (file and image tag) +* added support for all arguments to be passed as a string or an array + +== 0.1.0 2007-12-11 +* fixed the axis labels + +== 0.0.3 2007-12-11 +* added :chart_background alias and fixed a bug related to the background colors. + +== 0.0.2 2007-12-11 +* added support for more features and aliases + +== 0.0.1 2007-12-08 + +* 1 major enhancement: + * Initial release diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..8f67a70 --- /dev/null +++ b/License.txt @@ -0,0 +1,20 @@ +Copyright (c) 2007 Matt Aimonetti + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..cc75ee5 --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,18 @@ +History.txt +License.txt +Manifest.txt +README.txt +Rakefile +config/hoe.rb +config/requirements.rb +lib/gchart.rb +lib/gchart/aliases.rb +lib/gchart/theme.rb +lib/gchart/version.rb +setup.rb +spec/gchart_spec.rb +spec/theme_spec.rb +spec/spec.opts +spec/spec_helper.rb +tasks/environment.rake +tasks/rspec.rake diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..1361a29 --- /dev/null +++ b/README.markdown @@ -0,0 +1,290 @@ +The goal of this Gem is to make the creation of Google Charts a simple and easy task. + + Gchart.line( :size => '200x300', + :title => "example title", + :bg => 'efefef', + :legend => ['first data set label', 'second data set label'], + :data => [10, 30, 120, 45, 72]) + + +Check out the [full documentation over there](http://googlecharts.rubyforge.org/) + +This gem is fully tested using Rspec, check the rspec folder for more examples. + +See at the bottom of this file who reported using this gem. + +Chart Type +------------- + +This gem supports the following types of charts: + + * line, + * line_xy + * sparkline + * scatter + * bar + * venn + * pie + * pie_3d + * google meter + +Googlecharts also supports graphical themes and you can easily load your own. + +To create a chart, simply require Gchart and call any of the existing type: + + require 'gchart' + Gchart.pie + + +Chart Title +------------- + + To add a title to a chart pass the title to your chart: + + Gchart.line(:title => 'Sexy Charts!') + +You can also specify the color and/or size + + Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20') + +Colors +------------- + +Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example: + + * FF0000 = red + * 00FF00 = green + * 0000FF = blue + * 000000 = black + * FFFFFF = white + +You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example: + + * 0000FFFF = solid blue + * 0000FF00 = transparent blue + +If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00' + +Some charts have more options than other, make sure to refer to the documentation. + +Background options: +------------- + +If you don't set the background option, your graph will be transparent. + +* You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill + +- solid +- gradient +- stripes + +By default, if you set a background color, the fill will be solid: + + Gchart.bar(:bg => 'efefef') + +However you can specify another fill type such as: + + Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}) + +In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows: + + Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90}) + +For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient + + Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}) + + +The same way you set the background color, you can also set the graph background: + + Gchart.line(:graph_bg => 'cccccc') + +or both + + Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart') + + +Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes + + Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}) + +You can customize the amount of stripes, colors and width by changing the color value. + + +Themes +-------- + + Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from [Gruff](http://github.com/topfunky/gruff/tree/master) + + + Gchart.line( + :theme => :keynote, + :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]], + :title => 'keynote' + ) + + * keynote + + ![keynote](http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000) + + * thirty7signals + + ![37signals](http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF) + + * pastel + + ![pastel](http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) + + * greyscale + + ![greyscale](http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo) + + +You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml + +Load your theme(s): + + Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") + +And use the standard method signature to use your own theme: + + Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale') + + + +Legend & Labels +------------- + +You probably will want to use a legend or labels for your graph. + + Gchart.line(:legend => 'legend label') +or + Gchart.line(:legend => ['legend label 1', 'legend label 2']) + +Will do the trick. You can also use the labels alias (makes more sense when using the pie charts) + + chart = Gchart.pie(:labels => ['label 1', 'label 2']) + +Multiple axis labels +------------- + +Multiple axis labels are available for line charts, bar charts and scatter plots. + +* x = bottom x-axis +* t = top x-axis +* y = left y-axis +* r = right y-axis + + Gchart.line(:label_axis => 'x,y,r') + +To add labels on these axis: + + Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']) + + +Data options +------------- + +Data are passed using an array or a nested array. + + Gchart.bar(:data => [1,2,4,67,100,41,234]) + + Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]]) + +By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value. + + Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300) + Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto') + +or if you want to use the real values from your dataset: + + Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false) + + +You can also define a different encoding to add more granularity: + + Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple') + Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended') + Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text') + + +Pies: +------------- + +you have 2 type of pies: + - Gchart.pie() the standard 2D pie + _ Gchart.pie_3d() the fancy 3D pie + +To set labels, you can use one of these two options: + + @legend = ['Matt_fu', 'Rob_fu'] + Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200') + Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200') + +Bars: +------------- + +A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash. + +The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order: + + Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6 + Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12 + Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6 + Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25 + +The hash lets you set these values directly, with the Google default values set for any options you don't include: + + Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19}) + Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12}) + +Sparklines: +------------- + +A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default. + + +Google-o-meter +------------- + +A Google-o-meter has a few restrictions. It may only use a solid filled background and it may only have one label. + +try yourself +------------- + + Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]], + :title => 'SD Ruby Fu level', + :legend => ['matt','patrick'], + :bg => {:color => '76A4FB', :type => 'gradient'}, + :bar_colors => 'ff0000,00ff00') + + "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00" + + Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan']) +http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan + + +People reported using this gem: +--------------------- + +![github](http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png) + +* [http://github.com](http://github.com) + +![stafftool.com](http://stafftool.com/images/masthead_screen.gif) + +* [http://stafftool.com/](http://stafftool.com/) Takeo (contributor) + +![graffletopia.com](http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg) + +* [graffleropia.com](http://graffletopia.com) Mokolabs (contributor) + +![gumgum](http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg) + +* [http://gumgum.com](http://gumgum.com) Mattetti (Author) + +![http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg] + +* [http://feedflix.com/](http://feedflix.com/) [lifehacker article](http://lifehacker.com/395610/feedflix-creates-detailed-charts-from-your-netflix-use) + +* [California State University, Chico](http://www.csuchico.edu/) \ No newline at end of file diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..fdfe9df --- /dev/null +++ b/README.txt @@ -0,0 +1,9 @@ +CHECK README.markdown (open as a text file) + +Or check: + + http://googlecharts.rubyforge.org + +and/or + + http://github.com/mattetti/googlecharts \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..ed8e901 --- /dev/null +++ b/Rakefile @@ -0,0 +1,20 @@ +require 'rubygems' +require 'rake' + +begin + require 'jeweler' + Jeweler::Tasks.new do |gemspec| + gemspec.name = "googlecharts" + gemspec.summary = "Generate charts using Google API & Ruby" + gemspec.description = "Generate charts using Google API & Ruby" + gemspec.email = "[email protected]" + gemspec.homepage = "http://googlecharts.rubyforge.org/" + gemspec.authors = ["Matt Aimonetti"] + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" +end + +Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext } + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..94fe62c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.5.4 diff --git a/config/hoe.rb b/config/hoe.rb new file mode 100644 index 0000000..ae0b1da --- /dev/null +++ b/config/hoe.rb @@ -0,0 +1,71 @@ +require 'gchart/version' + +AUTHOR = 'Matt Aimonetti' # can also be an array of Authors +EMAIL = "[email protected]" +DESCRIPTION = "description of gem" +GEM_NAME = 'googlecharts' # what ppl will type to install your gem +RUBYFORGE_PROJECT = 'googlecharts' # The unix name for your project +HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org" +DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}" + +@config_file = "~/.rubyforge/user-config.yml" +@config = nil +RUBYFORGE_USERNAME = "matt_a" +def rubyforge_username + unless @config + begin + @config = YAML.load(File.read(File.expand_path(@config_file))) + rescue + puts <<-EOS +ERROR: No rubyforge config file found: #{@config_file} +Run 'rubyforge setup' to prepare your env for access to Rubyforge + - See http://newgem.rubyforge.org/rubyforge.html for more details + EOS + exit + end + end + RUBYFORGE_USERNAME.replace @config["username"] +end + + +REV = nil +# UNCOMMENT IF REQUIRED: +# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil +VERS = GchartInfo::VERSION::STRING + (REV ? ".#{REV}" : "") +RDOC_OPTS = ['--quiet', '--title', 'gchart documentation', + "--opname", "index.html", + "--line-numbers", + "--main", "README", + "--inline-source"] + +class Hoe + def extra_deps + @extra_deps.reject! { |x| Array(x).first == 'hoe' } + @extra_deps + end +end + +# Generate all the Rake tasks +# Run 'rake -T' to see list of generated tasks (from gem root directory) +hoe = Hoe.new(GEM_NAME, VERS) do |p| + p.author = AUTHOR + p.description = DESCRIPTION + p.email = EMAIL + p.summary = DESCRIPTION + p.url = HOMEPATH + p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT + p.test_globs = ["test/**/test_*.rb"] + p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean. + + # == Optional + p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") + #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ] + + #p.spec_extras = {} # A hash of extra values to set in the gemspec. + +end + +CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n") +PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}" +hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc') +hoe.rsync_args = '-av --delete --ignore-errors' \ No newline at end of file diff --git a/config/requirements.rb b/config/requirements.rb new file mode 100644 index 0000000..bf1b541 --- /dev/null +++ b/config/requirements.rb @@ -0,0 +1,16 @@ +require 'fileutils' +include FileUtils + +require 'rubygems' +%w[rake hoe newgem rubigen].each do |req_gem| + begin + require req_gem + rescue LoadError + puts "This Rakefile could use '#{req_gem}' RubyGem." + puts "Installation: gem install #{req_gem} -y" + end +end + +$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib])) + +require 'gchart' \ No newline at end of file diff --git a/lib/gchart.rb b/lib/gchart.rb new file mode 100644 index 0000000..1e62fde --- /dev/null +++ b/lib/gchart.rb @@ -0,0 +1,697 @@ +$:.unshift File.dirname(__FILE__) +require 'gchart/version' +require 'gchart/theme' +require "net/http" +require "uri" +require "cgi" +require 'enumerator' + +class Gchart + include GchartInfo + + def self.url + "http://chart.apis.google.com/chart?" + end + + def self.types + @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map'] + end + + def self.simple_chars + @simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + end + + def self.chars + @chars ||= simple_chars + ['-', '.'] + end + + def self.ext_pairs + @ext_pairs ||= chars.map { |char_1| chars.map { |char_2| char_1 + char_2 } }.flatten + end + + def self.default_filename + 'chart.png' + end + + attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :bar_colors, + :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass, + :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors + + attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines + + attr_accessor :min_value, :max_value + + types.each do |type| + instance_eval <<-DYNCLASSMETH + def #{type}(options = {}) + # Start with theme defaults if a theme is set + theme = options[:theme] + options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options + # # Extract the format and optional filename, then clean the hash + format = options[:format] || 'url' + options[:filename] ||= default_filename + options.delete(:format) + #update map_colors to become bar_colors + options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors) + chart = new(options.merge!({:type => "#{type}"})) + chart.send(format) + end + DYNCLASSMETH + end + + def self.version + VERSION::STRING + end + + def self.method_missing(m, options={}) + raise NoMethodError, "#{m} is not a supported chart format, please use one of the following: #{supported_types}." + end + + def initialize(options={}) + @type = options[:type] || 'line' + @data = [] + @width = 300 + @height = 200 + @horizontal = false + @grouped = false + @encoding = 'simple' + # @max_value = 'auto' + # @min_value defaults to nil meaning zero + @filename = options[:filename] + # Sets the alt tag when chart is exported as image tag + @alt = 'Google Chart' + # Sets the CSS id selector when chart is exported as image tag + @id = false + # Sets the CSS class selector when chart is exported as image tag + @klass = options[:class] || false + # set the options value if definable + options.each do |attribute, value| + send("#{attribute}=", value) if self.respond_to?("#{attribute}=") + end + end + + + def self.supported_types + self.class.types.join(' ') + end + + # Defines the Graph size using the following format: + # width X height + def size=(size='300x200') + @width, @height = size.split("x").map { |dimension| dimension.to_i } + end + + def size=(size='300x200') + @width, @height = size.split("x").map { |dimension| dimension.to_i } + end + + def size + "#{width}x#{height}" + end + + def dimensions + # TODO: maybe others? + [:line_xy, :scatter].include?(type) ? 2 : 1 + end + + # Sets the orientation of a bar graph + def orientation=(orientation='h') + if orientation == 'h' || orientation == 'horizontal' + self.horizontal = true + elsif orientation == 'v' || orientation == 'vertical' + self.horizontal = false + end + end + + # Sets the bar graph presentation (stacked or grouped) + def stacked=(option=true) + @grouped = option ? false : true + end + + def bg=(options) + if options.is_a?(String) + @bg_color = options + elsif options.is_a?(Hash) + @bg_color = options[:color] + @bg_type = options[:type] + @bg_angle = options[:angle] + end + end + + def graph_bg=(options) + if options.is_a?(String) + @chart_color = options + elsif options.is_a?(Hash) + @chart_color = options[:color] + @chart_type = options[:type] + @chart_angle = options[:angle] + end + end + + def max_value=(max_v) + if max_v =~ /false/ + @max_value = false + else + @max_value = max_v + end + end + + def min_value=(min_v) + if min_v =~ /false/ + @min_value = false + else + @min_value = min_v + end + end + + # returns the full data range as an array + # it also sets the data range if not defined + def full_data_range(ds) + return if max_value == false + + ds.each_with_index do |mds, mds_index| + mds[:min_value] ||= min_value + mds[:max_value] ||= max_value + + if mds_index == 0 && type.to_s == 'bar' + # TODO: unless you specify a zero line (using chp or chds), + # the min_value of a bar chart is always 0. + #mds[:min_value] ||= mds[:data].first.to_a.compact.min + mds[:min_value] ||= 0 + end + if (mds_index == 0 && type.to_s == 'bar' && + !grouped && mds[:data].first.is_a?(Array)) + totals = [] + mds[:data].each do |l| + l.each_with_index do |v, index| + next if v.nil? + totals[index] ||= 0 + totals[index] += v + end + end + mds[:max_value] ||= totals.compact.max + else + all = mds[:data].flatten.compact + # default min value should be 0 unless set to auto + if mds[:min_value] == 'auto' + mds[:min_value] = all.min + else + min = all.min + mds[:min_value] ||= (min && min < 0 ? min : 0) + end + mds[:max_value] ||= all.max + end + end + + unless axis_range + @calculated_axis_range = true + @axis_range = ds.map{|mds| [mds[:min_value], mds[:max_value]]} + if dimensions == 1 && (type.to_s != 'bar' || horizontal) + tmp = axis_range.fetch(0, []) + @axis_range[0] = axis_range.fetch(1, []) + @axis_range[1] = tmp + end + end + # return [min, max] unless (min.nil? || max.nil?) + # @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value + # + # if min_value.nil? + # min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0 + # @min = (min_ds_value < 0) ? min_ds_value : 0 + # else + # @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value + # end + # @axis_range = [[min,max]] + end + + def dataset + if @dataset + @dataset + else + @dataset = convert_dataset(data || []) + full_data_range(@dataset) # unless axis_range + @dataset + end + end + + # Sets of data to handle multiple sets + def datasets + datasets = [] + dataset.each do |d| + if d[:data].first.is_a?(Array) + datasets += d[:data] + else + datasets << d[:data] + end + end + datasets + end + + def self.jstize(string) + # See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347 + string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} + # string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"} + end + # load all the custom aliases + require 'gchart/aliases' + + # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org) + def fetch + url = URI.parse(self.class.url) + req = Net::HTTP::Post.new(url.path) + req.body = query_builder + req.content_type = 'application/x-www-form-urlencoded' + Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }.body + end + + # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org) + def write + io_or_file = filename || self.class.default_filename + return io_or_file.write(fetch) if io_or_file.respond_to?(:write) + open(io_or_file, "wb+") { |io| io.write(fetch) } + end + + # Format + + def image_tag + image = "<img" + image += " id=\"#{id}\"" if id + image += " class=\"#{klass}\"" if klass + image += " src=\"#{url_builder(:html)}\"" + image += " width=\"#{width}\"" + image += " height=\"#{height}\"" + image += " alt=\"#{alt}\"" + image += " title=\"#{title}\"" if title + image += " />" + end + + alias_method :img_tag, :image_tag + + def url + url_builder + end + + def file + write + end + + # + def jstize(string) + self.class.jstize(string) + end + + private + + # The title size cannot be set without specifying a color. + # A dark key will be used for the title color if no color is specified + def set_title + title_params = "chtt=#{title}" + unless (title_color.nil? && title_size.nil? ) + title_params << "&chts=" + (color, size = (title_color || '454545'), title_size).compact.join(',') + end + title_params + end + + def set_size + "chs=#{size}" + end + + def set_data + data = send("#{@encoding}_encoding") + "chd=#{data}" + end + + def set_colors + @bg_type = fill_type(bg_type) || 's' if bg_color + @chart_type = fill_type(chart_type) || 's' if chart_color + + "chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|') + end + + # set bar, line colors + def set_bar_colors + @bar_colors = bar_colors.join(',') if bar_colors.is_a?(Array) + "chco=#{bar_colors}" + end + + def set_country_codes + @country_codes = country_codes.join() if country_codes.is_a?(Array) + "chld=#{country_codes}" + end + + # set bar spacing + # chbh= + # <bar width in pixels>, + # <optional space between bars in a group>, + # <optional space between groups> + def set_bar_width_and_spacing + width_and_spacing_values = case bar_width_and_spacing + when String + bar_width_and_spacing + when Array + bar_width_and_spacing.join(',') + when Hash + width = bar_width_and_spacing[:width] || 23 + spacing = bar_width_and_spacing[:spacing] || 4 + group_spacing = bar_width_and_spacing[:group_spacing] || 8 + [width,spacing,group_spacing].join(',') + else + bar_width_and_spacing.to_s + end + "chbh=#{width_and_spacing_values}" + end + + def set_range_markers + markers = case range_markers + when Hash + set_range_marker(range_markers) + when Array + range_markers.collect{|marker| set_range_marker(marker)}.join('|') + end + "chm=#{markers}" + end + + def set_range_marker(options) + orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r' + "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}" + end + + def fill_for(type=nil, color='', angle=nil) + unless type.nil? + case type + when 'lg' + angle ||= 0 + color = "#{color},0,ffffff,1" if color.split(',').size == 1 + "#{type},#{angle},#{color}" + when 'ls' + angle ||= 90 + color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1 + "#{type},#{angle},#{color}" + else + "#{type},#{color}" + end + end + end + + # A chart can have one or many legends. + # Gchart.line(:legend => 'label') + # or + # Gchart.line(:legend => ['first label', 'last label']) + def set_legend + return set_labels if type.to_s =~ /pie|pie_3d|meter/ + + if legend.is_a?(Array) + "chdl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" + else + "chdl=#{legend}" + end + + end + + def set_line_thickness + "chls=#{thickness}" + end + + def set_line_markers + "chm=#{new_markers}" + end + + def set_grid_lines + "chg=#{grid_lines}" + end + + def set_labels + if legend.is_a?(Array) + "chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" + else + "chl=#{@legend}" + end + end + + def set_axis_with_labels + @axis_with_labels = axis_with_labels.join(',') if @axis_with_labels.is_a?(Array) + "chxt=#{axis_with_labels}" + end + + def set_axis_labels + if axis_labels.is_a?(Array) + if RUBY_VERSION.to_f < 1.9 + labels_arr = axis_labels.enum_with_index.map{|labels,index| [index,labels]} + else + labels_arr = axis_labels.map.with_index.map{|labels,index| [index,labels]} + end + elsif axis_labels.is_a?(Hash) + labels_arr = axis_labels.to_a + end + labels_arr.map! do |index,labels| + if labels.is_a?(Array) + "#{index}:|#{labels.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}" + else + "#{index}:|#{labels}" + end + end + count = labels_arr.length + + "chxl=#{labels_arr.join('|')}" + end + + # http://code.google.com/apis/chart/labels.html#axis_range + # Specify a range for axis labels + def set_axis_range + # a passed axis_range should look like: + # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]] + # in the second example, 4 is the interval + if @calculated_axis_range + set = datasets + else + set = axis_range || datasets + end + # in the case of a line graph, the first axis range should 1 + index_increase = type.to_s == 'line' ? 1 : 0 + if set && set.respond_to?(:each) && set.first.respond_to?(:each) + 'chxr=' + set.enum_for(:each_with_index).map do |range, index| + [(index + index_increase), (min_value || range.first), (max_value || range.last)].compact.join(',') + end.join("|") + else + nil + end + end + + def set_geographical_area + "chtm=#{geographical_area}" + end + + def set_type + case type.to_s + when 'line' + "cht=lc" + when 'line_xy' + "cht=lxy" + when 'bar' + "cht=b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s") + when 'pie_3d' + "cht=p3" + when 'pie' + "cht=p" + when 'venn' + "cht=v" + when 'scatter' + "cht=s" + when 'sparkline' + "cht=ls" + when 'meter' + "cht=gom" + when 'map' + "cht=t" + end + end + + def fill_type(type) + case type + when 'solid' + 's' + when 'gradient' + 'lg' + when 'stripes' + 'ls' + end + end + + def number_visible + n = 0 + dataset.each do |mds| + return n.to_s if mds[:invisible] == true + if mds[:data].first.is_a?(Array) + n += mds[:data].length + else + n += 1 + end + end + "" + end + + # Turns input into an array of axis hashes, dependent on the chart type + def convert_dataset(ds) + if dimensions == 2 + # valid inputs include: + # an array of >=2 arrays, or an array of >=2 hashes + ds = ds.map do |d| + d.is_a?(Hash) ? d : {:data => d} + end + elsif dimensions == 1 + # valid inputs include: + # a hash, an array of data, an array of >=1 array, or an array of >=1 hash + if ds.is_a?(Hash) + ds = [ds] + elsif not ds.first.is_a?(Hash) + ds = [{:data => ds}] + end + end + ds + end + + # just an alias + def axis_set + dataset + end + + def convert_to_simple_value(number) + if number.nil? + "_" + else + value = self.class.simple_chars[number.to_i] + value.nil? ? "_" : value + end + end + + def convert_to_extended_value(number) + if number.nil? + '__' + else + value = self.class.ext_pairs[number.to_i] + value.nil? ? "__" : value + end + end + + def encode_scaled_dataset(chars, nil_char) + dsets = [] + dataset.each do |ds| + if max_value != false + range = ds[:max_value] - ds[:min_value] + range = 1 if range == 0 + end + unless ds[:data].first.is_a?(Array) + ldatasets = [ds[:data]] + else + ldatasets = ds[:data] + end + ldatasets.each do |l| + dsets << l.map do |number| + if number.nil? + nil_char + else + unless range.nil? || range.zero? + number = chars.size * (number - ds[:min_value]) / range.to_f + number = [number, chars.size - 1].min + end + chars[number.to_i] + end + end.join + end + end + dsets.join(',') + end + + # http://code.google.com/apis/chart/#simple + # Simple encoding has a resolution of 62 different values. + # Allowing five pixels per data point, this is sufficient for line and bar charts up + # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size. + def simple_encoding + "s" + number_visible + ":" + encode_scaled_dataset(self.class.simple_chars, '_') + end + + # http://code.google.com/apis/chart/#text + # Text encoding with data scaling lets you specify arbitrary positive or + # negative floating point numbers, in combination with a scaling parameter + # that lets you specify a custom range for your chart. This chart is useful + # when you don't want to worry about limiting your data to a specific range, + # or do the calculations to scale your data down or up to fit nicely inside + # a chart. + # + # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not). + # + # This encoding is not available for maps. + # + def text_encoding + chds = dataset.map{|ds| "#{ds[:min_value]},#{ds[:max_value]}" }.join(",") + "t" + number_visible + ":" + datasets.map{ |ds| ds.join(',') }.join('|') + "&chds=" + chds + end + + # http://code.google.com/apis/chart/#extended + # Extended encoding has a resolution of 4,096 different values + # and is best used for large charts where a large data range is required. + def extended_encoding + "e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__') + end + + def url_builder(options="") + self.class.url + query_builder(options) + end + + def query_builder(options="") + query_params = instance_variables.sort.map do |var| + case var.to_s + when '@data' + set_data unless data == [] + # Set the graph size + when '@width' + set_size unless width.nil? || height.nil? + when '@type' + set_type + when '@title' + set_title unless title.nil? + when '@legend' + set_legend unless legend.nil? + when '@thickness' + set_line_thickness + when '@new_markers' + set_line_markers + when '@bg_color' + set_colors + when '@chart_color' + set_colors if bg_color.nil? + when '@bar_colors' + set_bar_colors + when '@bar_width_and_spacing' + set_bar_width_and_spacing + when '@axis_with_labels' + set_axis_with_labels + when '@axis_labels' + set_axis_labels + when '@range_markers' + set_range_markers + when '@grid_lines' + set_grid_lines + when '@geographical_area' + set_geographical_area + when '@country_codes' + set_country_codes + when '@custom' + custom + end + end.compact + + query_params << set_axis_range + + # Use ampersand as default delimiter + unless options == :html + delimiter = '&' + # Escape ampersand for html image tags + else + delimiter = '&amp;' + end + + jstize(query_params.join(delimiter)) + end + +end diff --git a/lib/gchart/aliases.rb b/lib/gchart/aliases.rb new file mode 100644 index 0000000..f7071fd --- /dev/null +++ b/lib/gchart/aliases.rb @@ -0,0 +1,14 @@ +class Gchart + + alias_method :background=, :bg= + alias_method :chart_bg=, :graph_bg= + alias_method :chart_color=, :graph_bg= + alias_method :chart_background=, :graph_bg= + alias_method :bar_color=, :bar_colors= + alias_method :line_colors=, :bar_colors= + alias_method :line_color=, :bar_colors= + alias_method :labels=, :legend= + alias_method :horizontal?, :horizontal + alias_method :grouped?, :grouped + +end \ No newline at end of file diff --git a/lib/gchart/theme.rb b/lib/gchart/theme.rb new file mode 100644 index 0000000..50a9901 --- /dev/null +++ b/lib/gchart/theme.rb @@ -0,0 +1,46 @@ +require 'yaml' + +module Chart + class Theme + class ThemeNotFound < RuntimeError; end + + @@theme_files = ["#{File.dirname(__FILE__)}/../themes.yml"] + + attr_accessor :colors + attr_accessor :bar_colors + attr_accessor :background + attr_accessor :chart_background + + def self.load(theme_name) + theme = new(theme_name) + end + + def self.theme_files + @@theme_files + end + + # Allows you to specify paths for custom theme files in YAML format + def self.add_theme_file(file) + @@theme_files << file + end + + def initialize(theme_name) + themes = {} + @@theme_files.each {|f| themes.update YAML::load(File.open(f))} + theme = themes[theme_name] + if theme + self.colors = theme[:colors] + self.bar_colors = theme[:bar_colors] + self.background = theme[:background] + self.chart_background = theme[:chart_background] + self + else + raise(ThemeNotFound, "Could not locate the #{theme_name} theme ...") + end + end + + def to_options + {:background => background, :chart_background => chart_background, :bar_colors => bar_colors.join(',')} + end + end +end \ No newline at end of file diff --git a/lib/gchart/version.rb b/lib/gchart/version.rb new file mode 100644 index 0000000..524cab3 --- /dev/null +++ b/lib/gchart/version.rb @@ -0,0 +1,9 @@ +module GchartInfo #:nodoc: + module VERSION #:nodoc: + MAJOR = 1 + MINOR = 5 + TINY = 4 + + STRING = [MAJOR, MINOR, TINY].join('.') + end +end diff --git a/lib/googlecharts.rb b/lib/googlecharts.rb new file mode 100644 index 0000000..da85077 --- /dev/null +++ b/lib/googlecharts.rb @@ -0,0 +1,2 @@ +require 'gchart' +Googlecharts = Gchart unless Object.const_defined? 'Googlechart' \ No newline at end of file diff --git a/lib/themes.yml b/lib/themes.yml new file mode 100644 index 0000000..061e9d3 --- /dev/null +++ b/lib/themes.yml @@ -0,0 +1,45 @@ +#Default themes ganked from Gruff: http://github.com/topfunky/gruff/tree/master +:keynote: + :colors: + - &blue 6886B4 + - &yellow FDD84E + - &green 72AE6E + - &red D1695E + - &purple 8A6EAF + - &orange EFAA43 + - &white FFFFFF + - &black !str 000000 + :bar_colors: [ *blue, *yellow, *green, *red, *purple, *orange ] + :background: *black + :chart_background: *white +:thirty7signals: + :colors: + - &green 339933 + - &purple cc99cc + - &blue 336699 + - &yellow FFF804 + - &red ff0000 + - &orange cf5910 + :bar_colors: [ *yellow, *blue, *green, *red, *purple, *orange ] + :background: *white +:pastel: + :colors: + - &blue a9dada + - &green aedaa9 + - &peach daaea9 + - &yellow dadaa9 + - &dk_purple a9a9da + - &purple daaeda + - &grey dadada + :bar_colors: [ *blue, *green, *peach, *yellow, *dk_purple ] + :background_color: *white +:greyscale: + :bar_colors: [ + 282828, + 383838, + 686868, + 989898, + c8c8c8, + e8e8e8 + ] + :background_color: *white \ No newline at end of file diff --git a/script/destroy b/script/destroy new file mode 100755 index 0000000..5fa7e10 --- /dev/null +++ b/script/destroy @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.join(File.dirname(__FILE__), '..') + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/destroy' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Destroy.new.run(ARGV) diff --git a/script/generate b/script/generate new file mode 100755 index 0000000..230a186 --- /dev/null +++ b/script/generate @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.join(File.dirname(__FILE__), '..') + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/generate' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Generate.new.run(ARGV) diff --git a/script/txt2html b/script/txt2html new file mode 100755 index 0000000..87198bc --- /dev/null +++ b/script/txt2html @@ -0,0 +1,74 @@ +#!/usr/bin/env ruby + +require 'rubygems' +begin + require 'newgem' +rescue LoadError + puts "\n\nGenerating the website requires the newgem RubyGem" + puts "Install: gem install newgem\n\n" + exit(1) +end +require 'redcloth' +require 'syntax/convertors/html' +require 'erb' +require File.dirname(__FILE__) + '/../lib/gchart' + +version = Gchart.version +download = 'http://rubyforge.org/projects/googlecharts' + +class Fixnum + def ordinal + # teens + return 'th' if (10..19).include?(self % 100) + # others + case self % 10 + when 1: return 'st' + when 2: return 'nd' + when 3: return 'rd' + else return 'th' + end + end +end + +class Time + def pretty + return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}" + end +end + +def convert_syntax(syntax, source) + return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'') +end + +if ARGV.length >= 1 + src, template = ARGV + template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml') + +else + puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html") + exit! +end + +template = ERB.new(File.open(template).read) + +title = nil +body = nil +File.open(src) do |fsrc| + title_text = fsrc.readline + body_text = fsrc.read + syntax_items = [] + body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){ + ident = syntax_items.length + element, syntax, source = $1, $2, $3 + syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>" + "syntax-temp-#{ident}" + } + title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip + body = RedCloth.new(body_text).to_html + body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] } +end +stat = File.stat(src) +created = stat.ctime +modified = stat.mtime + +$stdout << template.result(binding) diff --git a/setup.rb b/setup.rb new file mode 100644 index 0000000..424a5f3 --- /dev/null +++ b/setup.rb @@ -0,0 +1,1585 @@ +# +# setup.rb +# +# Copyright (c) 2000-2005 Minero Aoki +# +# This program is free software. +# You can distribute/modify this program under the terms of +# the GNU LGPL, Lesser General Public License version 2.1. +# + +unless Enumerable.method_defined?(:map) # Ruby 1.4.6 + module Enumerable + alias map collect + end +end + +unless File.respond_to?(:read) # Ruby 1.6 + def File.read(fname) + open(fname) {|f| + return f.read + } + end +end + +unless Errno.const_defined?(:ENOTEMPTY) # Windows? + module Errno + class ENOTEMPTY + # We do not raise this exception, implementation is not needed. + end + end +end + +def File.binread(fname) + open(fname, 'rb') {|f| + return f.read + } +end + +# for corrupted Windows' stat(2) +def File.dir?(path) + File.directory?((path[-1,1] == '/') ? path : path + '/') +end + + +class ConfigTable + + include Enumerable + + def initialize(rbconfig) + @rbconfig = rbconfig + @items = [] + @table = {} + # options + @install_prefix = nil + @config_opt = nil + @verbose = true + @no_harm = false + end + + attr_accessor :install_prefix + attr_accessor :config_opt + + attr_writer :verbose + + def verbose? + @verbose + end + + attr_writer :no_harm + + def no_harm? + @no_harm + end + + def [](key) + lookup(key).resolve(self) + end + + def []=(key, val) + lookup(key).set val + end + + def names + @items.map {|i| i.name } + end + + def each(&block) + @items.each(&block) + end + + def key?(name) + @table.key?(name) + end + + def lookup(name) + @table[name] or setup_rb_error "no such config item: #{name}" + end + + def add(item) + @items.push item + @table[item.name] = item + end + + def remove(name) + item = lookup(name) + @items.delete_if {|i| i.name == name } + @table.delete_if {|name, i| i.name == name } + item + end + + def load_script(path, inst = nil) + if File.file?(path) + MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path + end + end + + def savefile + '.config' + end + + def load_savefile + begin + File.foreach(savefile()) do |line| + k, v = *line.split(/=/, 2) + self[k] = v.strip + end + rescue Errno::ENOENT + setup_rb_error $!.message + "\n#{File.basename($0)} config first" + end + end + + def save + @items.each {|i| i.value } + File.open(savefile(), 'w') {|f| + @items.each do |i| + f.printf "%s=%s\n", i.name, i.value if i.value? and i.value + end + } + end + + def load_standard_entries + standard_entries(@rbconfig).each do |ent| + add ent + end + end + + def standard_entries(rbconfig) + c = rbconfig + + rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT']) + + major = c['MAJOR'].to_i + minor = c['MINOR'].to_i + teeny = c['TEENY'].to_i + version = "#{major}.#{minor}" + + # ruby ver. >= 1.4.4? + newpath_p = ((major >= 2) or + ((major == 1) and + ((minor >= 5) or + ((minor == 4) and (teeny >= 4))))) + + if c['rubylibdir'] + # V > 1.6.3 + libruby = "#{c['prefix']}/lib/ruby" + librubyver = c['rubylibdir'] + librubyverarch = c['archdir'] + siteruby = c['sitedir'] + siterubyver = c['sitelibdir'] + siterubyverarch = c['sitearchdir'] + elsif newpath_p + # 1.4.4 <= V <= 1.6.3 + libruby = "#{c['prefix']}/lib/ruby" + librubyver = "#{c['prefix']}/lib/ruby/#{version}" + librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}" + siteruby = c['sitedir'] + siterubyver = "$siteruby/#{version}" + siterubyverarch = "$siterubyver/#{c['arch']}" + else + # V < 1.4.4 + libruby = "#{c['prefix']}/lib/ruby" + librubyver = "#{c['prefix']}/lib/ruby/#{version}" + librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}" + siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby" + siterubyver = siteruby + siterubyverarch = "$siterubyver/#{c['arch']}" + end + parameterize = lambda {|path| + path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix') + } + + if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg } + makeprog = arg.sub(/'/, '').split(/=/, 2)[1] + else + makeprog = 'make' + end + + [ + ExecItem.new('installdirs', 'std/site/home', + 'std: install under libruby; site: install under site_ruby; home: install under $HOME')\ + {|val, table| + case val + when 'std' + table['rbdir'] = '$librubyver' + table['sodir'] = '$librubyverarch' + when 'site' + table['rbdir'] = '$siterubyver' + table['sodir'] = '$siterubyverarch' + when 'home' + setup_rb_error '$HOME was not set' unless ENV['HOME'] + table['prefix'] = ENV['HOME'] + table['rbdir'] = '$libdir/ruby' + table['sodir'] = '$libdir/ruby' + end + }, + PathItem.new('prefix', 'path', c['prefix'], + 'path prefix of target environment'), + PathItem.new('bindir', 'path', parameterize.call(c['bindir']), + 'the directory for commands'), + PathItem.new('libdir', 'path', parameterize.call(c['libdir']), + 'the directory for libraries'), + PathItem.new('datadir', 'path', parameterize.call(c['datadir']), + 'the directory for shared data'), + PathItem.new('mandir', 'path', parameterize.call(c['mandir']), + 'the directory for man pages'), + PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']), + 'the directory for system configuration files'), + PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']), + 'the directory for local state data'), + PathItem.new('libruby', 'path', libruby, + 'the directory for ruby libraries'), + PathItem.new('librubyver', 'path', librubyver, + 'the directory for standard ruby libraries'), + PathItem.new('librubyverarch', 'path', librubyverarch, + 'the directory for standard ruby extensions'), + PathItem.new('siteruby', 'path', siteruby, + 'the directory for version-independent aux ruby libraries'), + PathItem.new('siterubyver', 'path', siterubyver, + 'the directory for aux ruby libraries'), + PathItem.new('siterubyverarch', 'path', siterubyverarch, + 'the directory for aux ruby binaries'), + PathItem.new('rbdir', 'path', '$siterubyver', + 'the directory for ruby scripts'), + PathItem.new('sodir', 'path', '$siterubyverarch', + 'the directory for ruby extentions'), + PathItem.new('rubypath', 'path', rubypath, + 'the path to set to #! line'), + ProgramItem.new('rubyprog', 'name', rubypath, + 'the ruby program using for installation'), + ProgramItem.new('makeprog', 'name', makeprog, + 'the make program to compile ruby extentions'), + SelectItem.new('shebang', 'all/ruby/never', 'ruby', + 'shebang line (#!) editing mode'), + BoolItem.new('without-ext', 'yes/no', 'no', + 'does not compile/install ruby extentions') + ] + end + private :standard_entries + + def load_multipackage_entries + multipackage_entries().each do |ent| + add ent + end + end + + def multipackage_entries + [ + PackageSelectionItem.new('with', 'name,name...', '', 'ALL', + 'package names that you want to install'), + PackageSelectionItem.new('without', 'name,name...', '', 'NONE', + 'package names that you do not want to install') + ] + end + private :multipackage_entries + + ALIASES = { + 'std-ruby' => 'librubyver', + 'stdruby' => 'librubyver', + 'rubylibdir' => 'librubyver', + 'archdir' => 'librubyverarch', + 'site-ruby-common' => 'siteruby', # For backward compatibility + 'site-ruby' => 'siterubyver', # For backward compatibility + 'bin-dir' => 'bindir', + 'bin-dir' => 'bindir', + 'rb-dir' => 'rbdir', + 'so-dir' => 'sodir', + 'data-dir' => 'datadir', + 'ruby-path' => 'rubypath', + 'ruby-prog' => 'rubyprog', + 'ruby' => 'rubyprog', + 'make-prog' => 'makeprog', + 'make' => 'makeprog' + } + + def fixup + ALIASES.each do |ali, name| + @table[ali] = @table[name] + end + @items.freeze + @table.freeze + @options_re = /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/ + end + + def parse_opt(opt) + m = @options_re.match(opt) or setup_rb_error "config: unknown option #{opt}" + m.to_a[1,2] + end + + def dllext + @rbconfig['DLEXT'] + end + + def value_config?(name) + lookup(name).value? + end + + class Item + def initialize(name, template, default, desc) + @name = name.freeze + @template = template + @value = default + @default = default + @description = desc + end + + attr_reader :name + attr_reader :description + + attr_accessor :default + alias help_default default + + def help_opt + "--#{@name}=#{@template}" + end + + def value? + true + end + + def value + @value + end + + def resolve(table) + @value.gsub(%r<\$([^/]+)>) { table[$1] } + end + + def set(val) + @value = check(val) + end + + private + + def check(val) + setup_rb_error "config: --#{name} requires argument" unless val + val + end + end + + class BoolItem < Item + def config_type + 'bool' + end + + def help_opt + "--#{@name}" + end + + private + + def check(val) + return 'yes' unless val + case val + when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes' + when /\An(o)?\z/i, /\Af(alse)\z/i then 'no' + else + setup_rb_error "config: --#{@name} accepts only yes/no for argument" + end + end + end + + class PathItem < Item + def config_type + 'path' + end + + private + + def check(path) + setup_rb_error "config: --#{@name} requires argument" unless path + path[0,1] == '$' ? path : File.expand_path(path) + end + end + + class ProgramItem < Item + def config_type + 'program' + end + end + + class SelectItem < Item + def initialize(name, selection, default, desc) + super + @ok = selection.split('/') + end + + def config_type + 'select' + end + + private + + def check(val) + unless @ok.include?(val.strip) + setup_rb_error "config: use --#{@name}=#{@template} (#{val})" + end + val.strip + end + end + + class ExecItem < Item + def initialize(name, selection, desc, &block) + super name, selection, nil, desc + @ok = selection.split('/') + @action = block + end + + def config_type + 'exec' + end + + def value? + false + end + + def resolve(table) + setup_rb_error "$#{name()} wrongly used as option value" + end + + undef set + + def evaluate(val, table) + v = val.strip.downcase + unless @ok.include?(v) + setup_rb_error "invalid option --#{@name}=#{val} (use #{@template})" + end + @action.call v, table + end + end + + class PackageSelectionItem < Item + def initialize(name, template, default, help_default, desc) + super name, template, default, desc + @help_default = help_default + end + + attr_reader :help_default + + def config_type + 'package' + end + + private + + def check(val) + unless File.dir?("packages/#{val}") + setup_rb_error "config: no such package: #{val}" + end + val + end + end + + class MetaConfigEnvironment + def initialize(config, installer) + @config = config + @installer = installer + end + + def config_names + @config.names + end + + def config?(name) + @config.key?(name) + end + + def bool_config?(name) + @config.lookup(name).config_type == 'bool' + end + + def path_config?(name) + @config.lookup(name).config_type == 'path' + end + + def value_config?(name) + @config.lookup(name).config_type != 'exec' + end + + def add_config(item) + @config.add item + end + + def add_bool_config(name, default, desc) + @config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc) + end + + def add_path_config(name, default, desc) + @config.add PathItem.new(name, 'path', default, desc) + end + + def set_config_default(name, default) + @config.lookup(name).default = default + end + + def remove_config(name) + @config.remove(name) + end + + # For only multipackage + def packages + raise '[setup.rb fatal] multi-package metaconfig API packages() called for single-package; contact application package vendor' unless @installer + @installer.packages + end + + # For only multipackage + def declare_packages(list) + raise '[setup.rb fatal] multi-package metaconfig API declare_packages() called for single-package; contact application package vendor' unless @installer + @installer.packages = list + end + end + +end # class ConfigTable + + +# This module requires: #verbose?, #no_harm? +module FileOperations + + def mkdir_p(dirname, prefix = nil) + dirname = prefix + File.expand_path(dirname) if prefix + $stderr.puts "mkdir -p #{dirname}" if verbose? + return if no_harm? + + # Does not check '/', it's too abnormal. + dirs = File.expand_path(dirname).split(%r<(?=/)>) + if /\A[a-z]:\z/i =~ dirs[0] + disk = dirs.shift + dirs[0] = disk + dirs[0] + end + dirs.each_index do |idx| + path = dirs[0..idx].join('') + Dir.mkdir path unless File.dir?(path) + end + end + + def rm_f(path) + $stderr.puts "rm -f #{path}" if verbose? + return if no_harm? + force_remove_file path + end + + def rm_rf(path) + $stderr.puts "rm -rf #{path}" if verbose? + return if no_harm? + remove_tree path + end + + def remove_tree(path) + if File.symlink?(path) + remove_file path + elsif File.dir?(path) + remove_tree0 path + else + force_remove_file path + end + end + + def remove_tree0(path) + Dir.foreach(path) do |ent| + next if ent == '.' + next if ent == '..' + entpath = "#{path}/#{ent}" + if File.symlink?(entpath) + remove_file entpath + elsif File.dir?(entpath) + remove_tree0 entpath + else + force_remove_file entpath + end + end + begin + Dir.rmdir path + rescue Errno::ENOTEMPTY + # directory may not be empty + end + end + + def move_file(src, dest) + force_remove_file dest + begin + File.rename src, dest + rescue + File.open(dest, 'wb') {|f| + f.write File.binread(src) + } + File.chmod File.stat(src).mode, dest + File.unlink src + end + end + + def force_remove_file(path) + begin + remove_file path + rescue + end + end + + def remove_file(path) + File.chmod 0777, path + File.unlink path + end + + def install(from, dest, mode, prefix = nil) + $stderr.puts "install #{from} #{dest}" if verbose? + return if no_harm? + + realdest = prefix ? prefix + File.expand_path(dest) : dest + realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest) + str = File.binread(from) + if diff?(str, realdest) + verbose_off { + rm_f realdest if File.exist?(realdest) + } + File.open(realdest, 'wb') {|f| + f.write str + } + File.chmod mode, realdest + + File.open("#{objdir_root()}/InstalledFiles", 'a') {|f| + if prefix + f.puts realdest.sub(prefix, '') + else + f.puts realdest + end + } + end + end + + def diff?(new_content, path) + return true unless File.exist?(path) + new_content != File.binread(path) + end + + def command(*args) + $stderr.puts args.join(' ') if verbose? + system(*args) or raise RuntimeError, + "system(#{args.map{|a| a.inspect }.join(' ')}) failed" + end + + def ruby(*args) + command config('rubyprog'), *args + end + + def make(task = nil) + command(*[config('makeprog'), task].compact) + end + + def extdir?(dir) + File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb") + end + + def files_of(dir) + Dir.open(dir) {|d| + return d.select {|ent| File.file?("#{dir}/#{ent}") } + } + end + + DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn ) + + def directories_of(dir) + Dir.open(dir) {|d| + return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT + } + end + +end + + +# This module requires: #srcdir_root, #objdir_root, #relpath +module HookScriptAPI + + def get_config(key) + @config[key] + end + + alias config get_config + + # obsolete: use metaconfig to change configuration + def set_config(key, val) + @config[key] = val + end + + # + # srcdir/objdir (works only in the package directory) + # + + def curr_srcdir + "#{srcdir_root()}/#{relpath()}" + end + + def curr_objdir + "#{objdir_root()}/#{relpath()}" + end + + def srcfile(path) + "#{curr_srcdir()}/#{path}" + end + + def srcexist?(path) + File.exist?(srcfile(path)) + end + + def srcdirectory?(path) + File.dir?(srcfile(path)) + end + + def srcfile?(path) + File.file?(srcfile(path)) + end + + def srcentries(path = '.') + Dir.open("#{curr_srcdir()}/#{path}") {|d| + return d.to_a - %w(. ..) + } + end + + def srcfiles(path = '.') + srcentries(path).select {|fname| + File.file?(File.join(curr_srcdir(), path, fname)) + } + end + + def srcdirectories(path = '.') + srcentries(path).select {|fname| + File.dir?(File.join(curr_srcdir(), path, fname)) + } + end + +end + + +class ToplevelInstaller + + Version = '3.4.1' + Copyright = 'Copyright (c) 2000-2005 Minero Aoki' + + TASKS = [ + [ 'all', 'do config, setup, then install' ], + [ 'config', 'saves your configurations' ], + [ 'show', 'shows current configuration' ], + [ 'setup', 'compiles ruby extentions and others' ], + [ 'install', 'installs files' ], + [ 'test', 'run all tests in test/' ], + [ 'clean', "does `make clean' for each extention" ], + [ 'distclean',"does `make distclean' for each extention" ] + ] + + def ToplevelInstaller.invoke + config = ConfigTable.new(load_rbconfig()) + config.load_standard_entries + config.load_multipackage_entries if multipackage? + config.fixup + klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller) + klass.new(File.dirname($0), config).invoke + end + + def ToplevelInstaller.multipackage? + File.dir?(File.dirname($0) + '/packages') + end + + def ToplevelInstaller.load_rbconfig + if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg } + ARGV.delete(arg) + load File.expand_path(arg.split(/=/, 2)[1]) + $".push 'rbconfig.rb' + else + require 'rbconfig' + end + ::Config::CONFIG + end + + def initialize(ardir_root, config) + @ardir = File.expand_path(ardir_root) + @config = config + # cache + @valid_task_re = nil + end + + def config(key) + @config[key] + end + + def inspect + "#<#{self.class} #{__id__()}>" + end + + def invoke + run_metaconfigs + case task = parsearg_global() + when nil, 'all' + parsearg_config + init_installers + exec_config + exec_setup + exec_install + else + case task + when 'config', 'test' + ; + when 'clean', 'distclean' + @config.load_savefile if File.exist?(@config.savefile) + else + @config.load_savefile + end + __send__ "parsearg_#{task}" + init_installers + __send__ "exec_#{task}" + end + end + + def run_metaconfigs + @config.load_script "#{@ardir}/metaconfig" + end + + def init_installers + @installer = Installer.new(@config, @ardir, File.expand_path('.')) + end + + # + # Hook Script API bases + # + + def srcdir_root + @ardir + end + + def objdir_root + '.' + end + + def relpath + '.' + end + + # + # Option Parsing + # + + def parsearg_global + while arg = ARGV.shift + case arg + when /\A\w+\z/ + setup_rb_error "invalid task: #{arg}" unless valid_task?(arg) + return arg + when '-q', '--quiet' + @config.verbose = false + when '--verbose' + @config.verbose = true + when '--help' + print_usage $stdout + exit 0 + when '--version' + puts "#{File.basename($0)} version #{Version}" + exit 0 + when '--copyright' + puts Copyright + exit 0 + else + setup_rb_error "unknown global option '#{arg}'" + end + end + nil + end + + def valid_task?(t) + valid_task_re() =~ t + end + + def valid_task_re + @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/ + end + + def parsearg_no_options + unless ARGV.empty? + task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1) + setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}" + end + end + + alias parsearg_show parsearg_no_options + alias parsearg_setup parsearg_no_options + alias parsearg_test parsearg_no_options + alias parsearg_clean parsearg_no_options + alias parsearg_distclean parsearg_no_options + + def parsearg_config + evalopt = [] + set = [] + @config.config_opt = [] + while i = ARGV.shift + if /\A--?\z/ =~ i + @config.config_opt = ARGV.dup + break + end + name, value = *@config.parse_opt(i) + if @config.value_config?(name) + @config[name] = value + else + evalopt.push [name, value] + end + set.push name + end + evalopt.each do |name, value| + @config.lookup(name).evaluate value, @config + end + # Check if configuration is valid + set.each do |n| + @config[n] if @config.value_config?(n) + end + end + + def parsearg_install + @config.no_harm = false + @config.install_prefix = '' + while a = ARGV.shift + case a + when '--no-harm' + @config.no_harm = true + when /\A--prefix=/ + path = a.split(/=/, 2)[1] + path = File.expand_path(path) unless path[0,1] == '/' + @config.install_prefix = path + else + setup_rb_error "install: unknown option #{a}" + end + end + end + + def print_usage(out) + out.puts 'Typical Installation Procedure:' + out.puts " $ ruby #{File.basename $0} config" + out.puts " $ ruby #{File.basename $0} setup" + out.puts " # ruby #{File.basename $0} install (may require root privilege)" + out.puts + out.puts 'Detailed Usage:' + out.puts " ruby #{File.basename $0} <global option>" + out.puts " ruby #{File.basename $0} [<global options>] <task> [<task options>]" + + fmt = " %-24s %s\n" + out.puts + out.puts 'Global options:' + out.printf fmt, '-q,--quiet', 'suppress message outputs' + out.printf fmt, ' --verbose', 'output messages verbosely' + out.printf fmt, ' --help', 'print this message' + out.printf fmt, ' --version', 'print version and quit' + out.printf fmt, ' --copyright', 'print copyright and quit' + out.puts + out.puts 'Tasks:' + TASKS.each do |name, desc| + out.printf fmt, name, desc + end + + fmt = " %-24s %s [%s]\n" + out.puts + out.puts 'Options for CONFIG or ALL:' + @config.each do |item| + out.printf fmt, item.help_opt, item.description, item.help_default + end + out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's" + out.puts + out.puts 'Options for INSTALL:' + out.printf fmt, '--no-harm', 'only display what to do if given', 'off' + out.printf fmt, '--prefix=path', 'install path prefix', '' + out.puts + end + + # + # Task Handlers + # + + def exec_config + @installer.exec_config + @config.save # must be final + end + + def exec_setup + @installer.exec_setup + end + + def exec_install + @installer.exec_install + end + + def exec_test + @installer.exec_test + end + + def exec_show + @config.each do |i| + printf "%-20s %s\n", i.name, i.value if i.value? + end + end + + def exec_clean + @installer.exec_clean + end + + def exec_distclean + @installer.exec_distclean + end + +end # class ToplevelInstaller + + +class ToplevelInstallerMulti < ToplevelInstaller + + include FileOperations + + def initialize(ardir_root, config) + super + @packages = directories_of("#{@ardir}/packages") + raise 'no package exists' if @packages.empty? + @root_installer = Installer.new(@config, @ardir, File.expand_path('.')) + end + + def run_metaconfigs + @config.load_script "#{@ardir}/metaconfig", self + @packages.each do |name| + @config.load_script "#{@ardir}/packages/#{name}/metaconfig" + end + end + + attr_reader :packages + + def packages=(list) + raise 'package list is empty' if list.empty? + list.each do |name| + raise "directory packages/#{name} does not exist"\ + unless File.dir?("#{@ardir}/packages/#{name}") + end + @packages = list + end + + def init_installers + @installers = {} + @packages.each do |pack| + @installers[pack] = Installer.new(@config, + "#{@ardir}/packages/#{pack}", + "packages/#{pack}") + end + with = extract_selection(config('with')) + without = extract_selection(config('without')) + @selected = @installers.keys.select {|name| + (with.empty? or with.include?(name)) \ + and not without.include?(name) + } + end + + def extract_selection(list) + a = list.split(/,/) + a.each do |name| + setup_rb_error "no such package: #{name}" unless @installers.key?(name) + end + a + end + + def print_usage(f) + super + f.puts 'Inluded packages:' + f.puts ' ' + @packages.sort.join(' ') + f.puts + end + + # + # Task Handlers + # + + def exec_config + run_hook 'pre-config' + each_selected_installers {|inst| inst.exec_config } + run_hook 'post-config' + @config.save # must be final + end + + def exec_setup + run_hook 'pre-setup' + each_selected_installers {|inst| inst.exec_setup } + run_hook 'post-setup' + end + + def exec_install + run_hook 'pre-install' + each_selected_installers {|inst| inst.exec_install } + run_hook 'post-install' + end + + def exec_test + run_hook 'pre-test' + each_selected_installers {|inst| inst.exec_test } + run_hook 'post-test' + end + + def exec_clean + rm_f @config.savefile + run_hook 'pre-clean' + each_selected_installers {|inst| inst.exec_clean } + run_hook 'post-clean' + end + + def exec_distclean + rm_f @config.savefile + run_hook 'pre-distclean' + each_selected_installers {|inst| inst.exec_distclean } + run_hook 'post-distclean' + end + + # + # lib + # + + def each_selected_installers + Dir.mkdir 'packages' unless File.dir?('packages') + @selected.each do |pack| + $stderr.puts "Processing the package `#{pack}' ..." if verbose? + Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}") + Dir.chdir "packages/#{pack}" + yield @installers[pack] + Dir.chdir '../..' + end + end + + def run_hook(id) + @root_installer.run_hook id + end + + # module FileOperations requires this + def verbose? + @config.verbose? + end + + # module FileOperations requires this + def no_harm? + @config.no_harm? + end + +end # class ToplevelInstallerMulti + + +class Installer + + FILETYPES = %w( bin lib ext data conf man ) + + include FileOperations + include HookScriptAPI + + def initialize(config, srcroot, objroot) + @config = config + @srcdir = File.expand_path(srcroot) + @objdir = File.expand_path(objroot) + @currdir = '.' + end + + def inspect + "#<#{self.class} #{File.basename(@srcdir)}>" + end + + def noop(rel) + end + + # + # Hook Script API base methods + # + + def srcdir_root + @srcdir + end + + def objdir_root + @objdir + end + + def relpath + @currdir + end + + # + # Config Access + # + + # module FileOperations requires this + def verbose? + @config.verbose? + end + + # module FileOperations requires this + def no_harm? + @config.no_harm? + end + + def verbose_off + begin + save, @config.verbose = @config.verbose?, false + yield + ensure + @config.verbose = save + end + end + + # + # TASK config + # + + def exec_config + exec_task_traverse 'config' + end + + alias config_dir_bin noop + alias config_dir_lib noop + + def config_dir_ext(rel) + extconf if extdir?(curr_srcdir()) + end + + alias config_dir_data noop + alias config_dir_conf noop + alias config_dir_man noop + + def extconf + ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt + end + + # + # TASK setup + # + + def exec_setup + exec_task_traverse 'setup' + end + + def setup_dir_bin(rel) + files_of(curr_srcdir()).each do |fname| + update_shebang_line "#{curr_srcdir()}/#{fname}" + end + end + + alias setup_dir_lib noop + + def setup_dir_ext(rel) + make if extdir?(curr_srcdir()) + end + + alias setup_dir_data noop + alias setup_dir_conf noop + alias setup_dir_man noop + + def update_shebang_line(path) + return if no_harm? + return if config('shebang') == 'never' + old = Shebang.load(path) + if old + $stderr.puts "warning: #{path}: Shebang line includes too many args. It is not portable and your program may not work." if old.args.size > 1 + new = new_shebang(old) + return if new.to_s == old.to_s + else + return unless config('shebang') == 'all' + new = Shebang.new(config('rubypath')) + end + $stderr.puts "updating shebang: #{File.basename(path)}" if verbose? + open_atomic_writer(path) {|output| + File.open(path, 'rb') {|f| + f.gets if old # discard + output.puts new.to_s + output.print f.read + } + } + end + + def new_shebang(old) + if /\Aruby/ =~ File.basename(old.cmd) + Shebang.new(config('rubypath'), old.args) + elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby' + Shebang.new(config('rubypath'), old.args[1..-1]) + else + return old unless config('shebang') == 'all' + Shebang.new(config('rubypath')) + end + end + + def open_atomic_writer(path, &block) + tmpfile = File.basename(path) + '.tmp' + begin + File.open(tmpfile, 'wb', &block) + File.rename tmpfile, File.basename(path) + ensure + File.unlink tmpfile if File.exist?(tmpfile) + end + end + + class Shebang + def Shebang.load(path) + line = nil + File.open(path) {|f| + line = f.gets + } + return nil unless /\A#!/ =~ line + parse(line) + end + + def Shebang.parse(line) + cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ') + new(cmd, args) + end + + def initialize(cmd, args = []) + @cmd = cmd + @args = args + end + + attr_reader :cmd + attr_reader :args + + def to_s + "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}") + end + end + + # + # TASK install + # + + def exec_install + rm_f 'InstalledFiles' + exec_task_traverse 'install' + end + + def install_dir_bin(rel) + install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755 + end + + def install_dir_lib(rel) + install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644 + end + + def install_dir_ext(rel) + return unless extdir?(curr_srcdir()) + install_files rubyextentions('.'), + "#{config('sodir')}/#{File.dirname(rel)}", + 0555 + end + + def install_dir_data(rel) + install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644 + end + + def install_dir_conf(rel) + # FIXME: should not remove current config files + # (rename previous file to .old/.org) + install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644 + end + + def install_dir_man(rel) + install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644 + end + + def install_files(list, dest, mode) + mkdir_p dest, @config.install_prefix + list.each do |fname| + install fname, dest, mode, @config.install_prefix + end + end + + def libfiles + glob_reject(%w(*.y *.output), targetfiles()) + end + + def rubyextentions(dir) + ents = glob_select("*.#{@config.dllext}", targetfiles()) + if ents.empty? + setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first" + end + ents + end + + def targetfiles + mapdir(existfiles() - hookfiles()) + end + + def mapdir(ents) + ents.map {|ent| + if File.exist?(ent) + then ent # objdir + else "#{curr_srcdir()}/#{ent}" # srcdir + end + } + end + + # picked up many entries from cvs-1.11.1/src/ignore.c + JUNK_FILES = %w( + core RCSLOG tags TAGS .make.state + .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb + *~ *.old *.bak *.BAK *.orig *.rej _$* *$ + + *.org *.in .* + ) + + def existfiles + glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.'))) + end + + def hookfiles + %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt| + %w( config setup install clean ).map {|t| sprintf(fmt, t) } + }.flatten + end + + def glob_select(pat, ents) + re = globs2re([pat]) + ents.select {|ent| re =~ ent } + end + + def glob_reject(pats, ents) + re = globs2re(pats) + ents.reject {|ent| re =~ ent } + end + + GLOB2REGEX = { + '.' => '\.', + '$' => '\$', + '#' => '\#', + '*' => '.*' + } + + def globs2re(pats) + /\A(?:#{ + pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|') + })\z/ + end + + # + # TASK test + # + + TESTDIR = 'test' + + def exec_test + unless File.directory?('test') + $stderr.puts 'no test in this package' if verbose? + return + end + $stderr.puts 'Running tests...' if verbose? + begin + require 'test/unit' + rescue LoadError + setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.' + end + runner = Test::Unit::AutoRunner.new(true) + runner.to_run << TESTDIR + runner.run + end + + # + # TASK clean + # + + def exec_clean + exec_task_traverse 'clean' + rm_f @config.savefile + rm_f 'InstalledFiles' + end + + alias clean_dir_bin noop + alias clean_dir_lib noop + alias clean_dir_data noop + alias clean_dir_conf noop + alias clean_dir_man noop + + def clean_dir_ext(rel) + return unless extdir?(curr_srcdir()) + make 'clean' if File.file?('Makefile') + end + + # + # TASK distclean + # + + def exec_distclean + exec_task_traverse 'distclean' + rm_f @config.savefile + rm_f 'InstalledFiles' + end + + alias distclean_dir_bin noop + alias distclean_dir_lib noop + + def distclean_dir_ext(rel) + return unless extdir?(curr_srcdir()) + make 'distclean' if File.file?('Makefile') + end + + alias distclean_dir_data noop + alias distclean_dir_conf noop + alias distclean_dir_man noop + + # + # Traversing + # + + def exec_task_traverse(task) + run_hook "pre-#{task}" + FILETYPES.each do |type| + if type == 'ext' and config('without-ext') == 'yes' + $stderr.puts 'skipping ext/* by user option' if verbose? + next + end + traverse task, type, "#{task}_dir_#{type}" + end + run_hook "post-#{task}" + end + + def traverse(task, rel, mid) + dive_into(rel) { + run_hook "pre-#{task}" + __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '') + directories_of(curr_srcdir()).each do |d| + traverse task, "#{rel}/#{d}", mid + end + run_hook "post-#{task}" + } + end + + def dive_into(rel) + return unless File.dir?("#{@srcdir}/#{rel}") + + dir = File.basename(rel) + Dir.mkdir dir unless File.dir?(dir) + prevdir = Dir.pwd + Dir.chdir dir + $stderr.puts '---> ' + rel if verbose? + @currdir = rel + yield + Dir.chdir prevdir + $stderr.puts '<--- ' + rel if verbose? + @currdir = File.dirname(rel) + end + + def run_hook(id) + path = [ "#{curr_srcdir()}/#{id}", + "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) } + return unless path + begin + instance_eval File.read(path), path, 1 + rescue + raise if $DEBUG + setup_rb_error "hook #{path} failed:\n" + $!.message + end + end + +end # class Installer + + +class SetupError < StandardError; end + +def setup_rb_error(msg) + raise SetupError, msg +end + +if $0 == __FILE__ + begin + ToplevelInstaller.invoke + rescue SetupError + raise if $DEBUG + $stderr.puts $!.message + $stderr.puts "Try 'ruby #{$0} --help' for detailed usage." + exit 1 + end +end diff --git a/spec/fixtures/another_test_theme.yml b/spec/fixtures/another_test_theme.yml new file mode 100644 index 0000000..f5a3449 --- /dev/null +++ b/spec/fixtures/another_test_theme.yml @@ -0,0 +1,8 @@ +:test_two: + :colors: + - &blue 6886B4 + - &yellow FDD84E + - &grey 333333 + :bar_colors: [ *blue, *yellow ] + :background: *grey + :chart_background: *grey diff --git a/spec/fixtures/test_theme.yml b/spec/fixtures/test_theme.yml new file mode 100644 index 0000000..ac4f4a6 --- /dev/null +++ b/spec/fixtures/test_theme.yml @@ -0,0 +1,8 @@ +:test: + :colors: + - &blue 6886B4 + - &yellow FDD84E + - &white FFFFFF + :bar_colors: [ *blue, *yellow ] + :background: *white + :chart_background: *white \ No newline at end of file diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb new file mode 100644 index 0000000..194e840 --- /dev/null +++ b/spec/gchart_spec.rb @@ -0,0 +1,607 @@ +require File.dirname(__FILE__) + '/spec_helper.rb' +require File.dirname(__FILE__) + '/../lib/gchart' + +Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml") + +# Time to add your specs! +# http://rspec.rubyforge.org/ +describe "generating a default Gchart" do + + before(:each) do + @chart = Gchart.line + end + + it "should include the Google URL" do + @chart.include?("http://chart.apis.google.com/chart?").should be_true + end + + it "should have a default size" do + @chart.should include('chs=300x200') + end + + it "should be able to have a custom size" do + Gchart.line(:size => '400x600').include?('chs=400x600').should be_true + Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true + end + + it "should have query parameters in predictable order" do + Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxt=.+cht=.+chs=/) + end + + it "should have a type" do + @chart.include?('cht=lc').should be_true + end + + it 'should use theme defaults if theme is set' do + Gchart.line(:theme=>:test).should include('chco=6886B4,FDD84E') + if RUBY_VERSION.to_f < 1.9 + Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')) + else + Gchart.line(:theme=>:test).should include(Gchart.jstize('chf=bg,s,FFFFFF|c,s,FFFFFF')) + end + end + + it "should use the simple encoding by default with auto max value" do + # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9 + Gchart.line(:data => [0, 26]).should include('chd=s:A9') + Gchart.line(:data => [0, 26], :max_value => 26).should include('chxr=1,0,26') + end + + it "should support simple encoding with and without max_value" do + Gchart.line(:data => [0, 26], :max_value => 26).should include('chd=s:A9') + Gchart.line(:data => [0, 26], :max_value => false).should include('chd=s:Aa') + end + + it "should support the extended encoding and encode properly" do + Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true + Gchart.line(:encoding => 'extended', + :max_value => false, + :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]] + ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true + end + + it "should auto set the max value for extended encoding" do + Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).should include('chd=e:AAAZ') + # Extended encoding max value is '..' + Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true + end + + it "should be able to have data with text encoding" do + Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chd=t:10,5.2,4,45,78') + end + + it "should handle max and min values with text encoding" do + Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=0,78') + end + + it "should automatically handle negative values with proper max/min limits when using text encoding" do + Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').should include('chds=-10,78') + end + + it "should handle negative values with manual max/min limits when using text encoding" do + Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true + end + + it "should set the proper axis values when using text encoding and negative values" do + Gchart.bar( :data => [[-10], [100]], + :encoding => 'text', + :horizontal => true, + :min_value => -20, + :max_value => 100, + :axis_with_labels => 'x', + :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100") + end + + it "should be able to have muliple set of data with text encoding" do + Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true + end + + it "should be able to receive a custom param" do + Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true + end + + it "should be able to set label axis" do + Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true + Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true + end + + it "should be able to have axis labels" do + Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true + Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true + Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true + Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true + end + + it "should display ranges properly" do + data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] + url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)]) + url.should include('chxr=1,85,593') + end + + it "should force the y range properly" do + url = Gchart.bar(:data => [1,1,1,1,1,1,1,1,6,2,1,1], + :axis_with_labels => 'x,y', + :min_value => 0, + :max_value => 16, + :axis_labels => [1.upto(12).to_a], + :axis_range => [[0,0],[0,16]], + :encoding => "text" + ) + url.should include('chxr=0,0,16|1,0,16') + end + + it "should take in consideration the max value when creating a range" do + data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593] + url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)], :max_value => 700) + url.should include('chxr=1,85,700') + end + +end + +describe "generating different type of charts" do + + it "should be able to generate a line chart" do + Gchart.line.should be_an_instance_of(String) + Gchart.line.include?('cht=lc').should be_true + end + + it "should be able to generate a sparkline chart" do + Gchart.sparkline.should be_an_instance_of(String) + Gchart.sparkline.include?('cht=ls').should be_true + end + + it "should be able to generate a line xy chart" do + Gchart.line_xy.should be_an_instance_of(String) + Gchart.line_xy.include?('cht=lxy').should be_true + end + + it "should be able to generate a scatter chart" do + Gchart.scatter.should be_an_instance_of(String) + Gchart.scatter.include?('cht=s').should be_true + end + + it "should be able to generate a bar chart" do + Gchart.bar.should be_an_instance_of(String) + Gchart.bar.include?('cht=bvs').should be_true + end + + it "should be able to generate a Venn diagram" do + Gchart.venn.should be_an_instance_of(String) + Gchart.venn.include?('cht=v').should be_true + end + + it "should be able to generate a Pie Chart" do + Gchart.pie.should be_an_instance_of(String) + Gchart.pie.include?('cht=p').should be_true + end + + it "should be able to generate a Google-O-Meter" do + Gchart.meter.should be_an_instance_of(String) + Gchart.meter.include?('cht=gom').should be_true + end + + it "should be able to generate a map chart" do + Gchart.map.should be_an_instance_of(String) + Gchart.map.include?('cht=t').should be_true + end + + it "should not support other types" do + lambda{Gchart.sexy}.should raise_error + # msg => "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}." + end + +end + + +describe "range markers" do + + it "should be able to generate given a hash of range-marker options" do + Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true + end + + it "should be able to generate given an array of range-marker hash options" do + Gchart.line(:range_markers => [ + {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}, + {:start_position => 0, :stop_position => 0.6, :color => '666666'}, + {:color => 'cccccc', :start_position => 0.6, :stop_position => 1} + ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true + end + + it "should allow a :overlaid? to be set" do + Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true + Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true + end + + describe "when setting the orientation option" do + before(:each) do + options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'} + end + + it "to vertical (R) if given a valid option" do + Gchart.line(:range_markers => options.merge(:orientation => 'v')).include?('chm=R').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'V')).include?('chm=R').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'R')).include?('chm=R').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'vertical')).include?('chm=R').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true + end + + it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do + Gchart.line(:range_markers => options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'h')).include?('chm=r').should be_true + Gchart.line(:range_markers => options.merge(:orientation => 'etc')).include?('chm=r').should be_true + end + + it "if left blank defaults to horizontal (r)" do + Gchart.line(:range_markers => options).include?('chm=r').should be_true + end + end + +end + + +describe "a bar graph" do + + it "should have a default vertical orientation" do + Gchart.bar.include?('cht=bvs').should be_true + end + + it "should be able to have a different orientation" do + Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true + Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true + Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true + Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true + Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true + end + + it "should be set to be stacked by default" do + Gchart.bar.include?('cht=bvs').should be_true + end + + it "should be able to stacked or grouped" do + Gchart.bar(:stacked => true).include?('cht=bvs').should be_true + Gchart.bar(:stacked => false).include?('cht=bvg').should be_true + Gchart.bar(:grouped => true).include?('cht=bvg').should be_true + Gchart.bar(:grouped => false).include?('cht=bvs').should be_true + end + + it "should be able to have different bar colors" do + Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true + Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true + # alias + Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true + end + + it "should be able to have different bar colors when using an array of colors" do + Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true + end + + it 'should be able to accept a string of width and spacing options' do + Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true + end + + it 'should be able to accept a single fixnum width and spacing option to set the bar width' do + Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true + end + + it 'should be able to accept an array of width and spacing options' do + Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true + Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true + Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true + end + + describe "with a hash of width and spacing options" do + + before(:each) do + @default_width = 23 + @default_spacing = 4 + @default_group_spacing = 8 + end + + it 'should be able to have a custom bar width' do + Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true + end + + it 'should be able to have custom spacing' do + Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true + end + + it 'should be able to have custom group spacing' do + Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true + end + + end + +end + +describe "a line chart" do + + before(:each) do + @title = 'Chart Title' + @legend = ['first data set label', 'n data set label'] + @chart = Gchart.line(:title => @title, :legend => @legend) + end + + it 'should be able have a chart title' do + @chart.include?("chtt=Chart+Title").should be_true + end + + it "should be able to a custom color and size title" do + Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true + Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true + end + + it "should be able to have multiple legends" do + @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true + end + + it "should escape text values in url" do + title = 'Chart & Title' + legend = ['first data & set label', 'n data set label'] + chart = Gchart.line(:title => title, :legend => legend) + chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true + end + + it "should be able to have one legend" do + chart = Gchart.line(:legend => 'legend label') + chart.include?("chdl=legend+label").should be_true + end + + it "should be able to set the background fill" do + Gchart.line(:bg => 'efefef').should include("chf=bg,s,efefef") + Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).should include("chf=bg,s,efefef") + + Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") + Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).should include("chf=bg,lg,0,efefef,0,ffffff,1") + Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).should include("chf=bg,lg,90,efefef,0,ffffff,1") + + Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).should include("chf=bg,ls,90,efefef,0.2,ffffff,0.2") + end + + it "should be able to set a graph fill" do + Gchart.line(:graph_bg => 'efefef').should include("chf=c,s,efefef") + Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true + Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true + Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true + Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true + end + + it "should be able to set both a graph and a background fill" do + Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true + Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true + if RUBY_VERSION.to_f < 1.9 + Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true + else + Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true + end + end + + it "should be able to have different line colors" do + Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true + Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true + end + + it "should be able to render a graph where all the data values are 0" do + Gchart.line(:data => [0, 0, 0]).should include("chd=s:AAA") + end + +end + +describe "a sparkline chart" do + + before(:each) do + @title = 'Chart Title' + @legend = ['first data set label', 'n data set label'] + @jstized_legend = Gchart.jstize(@legend.join('|')) + @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] + @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend) + end + + it "should create a sparkline" do + @chart.include?('cht=ls').should be_true + end + + it 'should be able have a chart title' do + @chart.include?("chtt=Chart+Title").should be_true + end + + it "should be able to a custom color and size title" do + Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true + Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true + end + + it "should be able to have multiple legends" do + @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true + end + + it "should be able to have one legend" do + chart = Gchart.sparkline(:legend => 'legend label') + chart.include?("chdl=legend+label").should be_true + end + + it "should be able to set the background fill" do + Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true + Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true + + Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true + Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true + Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true + + Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true + end + + it "should be able to set a graph fill" do + Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true + Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true + Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true + Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true + Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true + end + + it "should be able to set both a graph and a background fill" do + Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true + Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true + if RUBY_VERSION.to_f < 1.9 + Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true + else + Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=bg,s,efefef|c,s,76A4FB")).should be_true + end + end + + it "should be able to have different line colors" do + Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true + Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true + end + +end + +describe "a 3d pie chart" do + + before(:each) do + @title = 'Chart Title' + @legend = ['first data set label', 'n data set label'] + @jstized_legend = Gchart.jstize(@legend.join('|')) + @data = [12,8,40,15,5] + @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data) + end + + it "should create a pie" do + @chart.include?('cht=p').should be_true + end + + it "should be able to be in 3d" do + Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true + end + + it "should be able to set labels by using the legend or labesl accessor" do + Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).should include("chl=#{@jstized_legend}") + Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should include("chl=#{@jstized_legend}") + Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data) + end + +end + +describe "a google-o-meter" do + + before(:each) do + @data = [70] + @legend = ['arrow points here'] + @jstized_legend = Gchart.jstize(@legend.join('|')) + @chart = Gchart.meter(:data => @data) + end + + it "should create a meter" do + @chart.include?('cht=gom').should be_true + end + + it "should be able to set a solid background fill" do + Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true + Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true + end + +end + +describe "a map chart" do + + before(:each) do + @data = [0,100,50,32] + @geographical_area = 'usa' + @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00'] + @country_codes = ['MT', 'WY', "ID", 'SD'] + @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300', + :geographical_area => @geographical_area, :map_colors => @map_colors, + :country_codes => @country_codes) + end + + it "should create a map" do + @chart.include?('cht=t').should be_true + end + + it "should set the geographical area" do + @chart.include?('chtm=usa').should be_true + end + + it "should set the map colors" do + @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true + end + + it "should set the country/state codes" do + @chart.include?('chld=MTWYIDSD').should be_true + end + + it "should set the chart data" do + @chart.include?('chd=t:0,100,50,32').should be_true + end + +end + +describe 'exporting a chart' do + + it "should be available in the url format by default" do + Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26]) + end + + it "should be available as an image tag" do + Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) + end + + it "should be available as an image tag using img_tag alias" do + Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/) + end + + it "should be available as an image tag using custom dimensions" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/) + end + + it "should be available as an image tag using custom alt text" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/) + end + + it "should be available as an image tag using custom title text" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/) + end + + it "should be available as an image tag using custom css id selector" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) + end + + it "should be available as an image tag using custom css class selector" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/) + end + + it "should use ampersands to separate key/value pairs in URLs by default" do + Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" } + Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" } + end + + it "should escape ampersands in URLs when used as an image tag" do + Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" } + end + + it "should be available as a file" do + File.delete('chart.png') if File.exist?('chart.png') + Gchart.line(:data => [0, 26], :format => 'file') + File.exist?('chart.png').should be_true + File.delete('chart.png') if File.exist?('chart.png') + end + + it "should be available as a file using a custom file name" do + File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') + Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png') + File.exist?('custom_file_name.png').should be_true + File.delete('custom_file_name.png') if File.exist?('custom_file_name.png') + end + + it "should work even with multiple attrs" do + File.delete('foo.png') if File.exist?('foo.png') + Gchart.line(:size => '400x200', + :data => [1,2,3,4,5], + # :axis_labels => [[1,2,3,4, 5], %w[foo bar]], + :axis_with_labels => 'x,r', + :format => "file", + :filename => "foo.png" + ) + File.exist?('foo.png').should be_true + File.delete('foo.png') if File.exist?('foo.png') + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..f1ca062 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,7 @@ +begin + require 'spec' +rescue LoadError + require 'rubygems' + gem 'rspec' + require 'spec' +end \ No newline at end of file diff --git a/spec/theme_spec.rb b/spec/theme_spec.rb new file mode 100644 index 0000000..ce88d74 --- /dev/null +++ b/spec/theme_spec.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/spec_helper.rb' +require File.dirname(__FILE__) + '/../lib/gchart' + +describe "generating a default Gchart" do + it 'should be able to add additional theme files' do + Chart::Theme.theme_files.should_not include("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") + Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") + Chart::Theme.theme_files.should include("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") + end + + it 'should be able to load themes from the additional theme files' do + lambda { Chart::Theme.load(:test_two) }.should_not raise_error + end + + it 'should raise ThemeNotFound if theme does not exist' do + lambda { Chart::Theme.load(:nonexistent) }.should raise_error(Chart::Theme::ThemeNotFound, "Could not locate the nonexistent theme ...") + end + + it 'should set colors array' do + Chart::Theme.load(:keynote).colors.should eql(["6886B4", "FDD84E", "72AE6E", "D1695E", "8A6EAF", "EFAA43", "FFFFFF", "000000"]) + end + + it 'should set bar colors array' do + Chart::Theme.load(:keynote).bar_colors.should eql(["6886B4", "FDD84E", "72AE6E", "D1695E", "8A6EAF", "EFAA43"]) + end + + it 'should set background' do + Chart::Theme.load(:keynote).background.should eql("000000") + end + + it 'should set chart background' do + Chart::Theme.load(:keynote).chart_background.should eql("FFFFFF") + end +end \ No newline at end of file diff --git a/tasks/deployment.rake b/tasks/deployment.rake new file mode 100644 index 0000000..2f43742 --- /dev/null +++ b/tasks/deployment.rake @@ -0,0 +1,34 @@ +desc 'Release the website and new gem version' +task :deploy => [:check_version, :website, :release] do + puts "Remember to create SVN tag:" + puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " + + "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} " + puts "Suggested comment:" + puts "Tagging release #{CHANGES}" +end + +desc 'Runs tasks website_generate and install_gem as a local deployment of the gem' +task :local_deploy => [:website_generate, :install_gem] + +task :check_version do + unless ENV['VERSION'] + puts 'Must pass a VERSION=x.y.z release version' + exit + end + unless ENV['VERSION'] == VERS + puts "Please update your version.rb to match the release version, currently #{VERS}" + exit + end +end + +desc 'Install the package as a gem, without generating documentation(ri/rdoc)' +task :install_gem_no_doc => [:clean, :package] do + sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri" +end + +namespace :manifest do + desc 'Recreate Manifest.txt to include ALL files' + task :refresh do + `rake check_manifest | patch -p0 > Manifest.txt` + end +end \ No newline at end of file diff --git a/tasks/environment.rake b/tasks/environment.rake new file mode 100644 index 0000000..691ed3b --- /dev/null +++ b/tasks/environment.rake @@ -0,0 +1,7 @@ +task :ruby_env do + RUBY_APP = if RUBY_PLATFORM =~ /java/ + "jruby" + else + "ruby" + end unless defined? RUBY_APP +end diff --git a/tasks/rspec.rake b/tasks/rspec.rake new file mode 100644 index 0000000..b256d1c --- /dev/null +++ b/tasks/rspec.rake @@ -0,0 +1,21 @@ +begin + require 'spec' +rescue LoadError + require 'rubygems' + require 'spec' +end +begin + require 'spec/rake/spectask' +rescue LoadError + puts <<-EOS +To use rspec for testing you must install rspec gem: + gem install rspec +EOS + exit(0) +end + +desc "Run the specs under spec/models" +Spec::Rake::SpecTask.new do |t| + t.spec_opts = ['--options', "spec/spec.opts"] + t.spec_files = FileList['spec/*_spec.rb'] +end diff --git a/tasks/website.rake b/tasks/website.rake new file mode 100644 index 0000000..93e03fa --- /dev/null +++ b/tasks/website.rake @@ -0,0 +1,17 @@ +desc 'Generate website files' +task :website_generate => :ruby_env do + (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt| + sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} } + end +end + +desc 'Upload website files to rubyforge' +task :website_upload do + host = "#{rubyforge_username}@rubyforge.org" + remote_dir = "/var/www/gforge-projects/#{PATH}/" + local_dir = 'website' + sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}} +end + +desc 'Generate and upload website files' +task :website => [:website_generate, :website_upload, :publish_docs] diff --git a/website/index.html b/website/index.html new file mode 100644 index 0000000..a51f679 --- /dev/null +++ b/website/index.html @@ -0,0 +1,732 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" /> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title> + Googlecharts + </title> + <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script> +<style> + +</style> + <script type="text/javascript"> + window.onload = function() { + settings = { + tl: { radius: 10 }, + tr: { radius: 10 }, + bl: { radius: 10 }, + br: { radius: 10 }, + antiAlias: true, + autoPad: true, + validTags: ["div"] + } + var versionBox = new curvyCorners(settings, document.getElementById("version")); + versionBox.applyCornersToAll(); + } + </script> +</head> +<body> +<div id="main"> + + <h1>Googlecharts</h1> + <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/googlecharts"; return false'> + <p>Get Version</p> + <a href="http://rubyforge.org/projects/googlecharts" class="numbers">1.3.4</a> + </div> + <h2>&#x2192; &#8216;Sexy Charts using Google <span class="caps">API</span> &#38; Ruby&#8217;</h2> + + + <h2>What</h2> + + + <p>A nice and simple wrapper for <a href="http://code.google.com/apis/chart/">Google Chart <span class="caps">API</span></a> +(Fully tested using RSpec, check the specs for more usage examples)</p> + + + <h2>Installing</h2> + + + <p>This project is now hosted at <a href="http://github.com">GitHub</a> +If you never added <a href="http://github.com">GitHub</a> as a gem source, you will need to do the following: +<pre class='syntax'><span class="global">$ </span><span class="ident">gem</span> <span class="ident">sources</span> <span class="punct">-</span><span class="ident">a</span> <span class="ident">http</span><span class="punct">:/</span><span class="regex"></span><span class="punct">/</span><span class="ident">gems</span><span class="punct">.</span><span class="ident">github</span><span class="punct">.</span><span class="ident">com</span><span class="punct">/</span></pre> (you only need to do this once)</p> + + + <p><pre class='syntax'><span class="global">$ </span><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">mattetti</span><span class="punct">-</span><span class="ident">googlecharts</span></pre></p> + + + <p>or <pre class='syntax'><span class="global">$ </span><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">googlecharts</span></pre></p> + + + <h2>The basics</h2> + + + <p>This gem supports the following types of charts:</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=200x125&#38;chd=s:helloWorld&#38;chxt=x,y&#38;chxl=0:|Mar|Apr|May|June|July|1:||50+Kb" title="Line" alt="Line" /> Gchart.line()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lxy&#38;chs=200x125&#38;chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&#38;chco=3072F3,ff0000,00aaaa&#38;chls=2,4,1&#38;chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5" title="line_xy" alt="line_xy" /> Gchart.line_xy()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=s&#38;chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&#38;chxt=x,y&#38;chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&#38;chs=200x125" title="scatter" alt="scatter" /> Gchart.scatter()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvg&#38;chs=200x125&#38;chd=s:hello,world&#38;chco=cc0000,00aa00" title="bar" alt="bar" /> Gchart.bar()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=v&#38;chs=200x100&#38;chd=t:100,80,60,30,30,30,10" title="venn" alt="venn" /> Gchart.venn()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=p&#38;chd=s:world5&#38;chs=200x125&#38;chl=A|B|C|D|E|Fe" title="pie" alt="pie" /> Gchart.pie()</p> + + + <p><img src="http://chart.apis.google.com/chart?cht=p3&#38;chd=s:Uf9a&#38;chs=200x100&#38;chl=A|B|C|D" title="pie_3d" alt="pie_3d" /> Gchart.pie_3d()</p> + + + <p><img src="http://chart.apis.google.com/chart?chs=100x20&#38;cht=ls&#38;chco=0077CC&#38;chm=B,E6F2FA,0,0,0&#38;chls=1,0,0&#38;chd=t:27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25" title="sparkline" alt="sparkline" />Gchart.sparkline()</p> + + + <p><img src="http://chart.apis.google.com/chart?chs=225x125&#38;cht=gom&#38;chd=t:70&#38;chl=Flavor" title="google-o-meter" alt="google-o-meter" /> Gchart.meter()</p> + + + <h2>Demonstration of usage</h2> + + + <p>install:</p> + + +<code>sudo gem install mattetti-googlecharts</code> + + <p>or use rubyforge:</p> + + +<code>sudo gem install googlecharts</code> + + <p>require: +<pre class='syntax'><span class="ident">require</span> <span class="punct">'</span><span class="string">gchart</span><span class="punct">'</span></pre></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">200x300</span><span class="punct">',</span> + <span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">example title</span><span class="punct">&quot;,</span> + <span class="symbol">:bg</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">efefef</span><span class="punct">',</span> + <span class="symbol">:legend</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">first data set label</span><span class="punct">',</span> <span class="punct">'</span><span class="string">second data set label</span><span class="punct">'],</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">10</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">120</span><span class="punct">,</span> <span class="number">45</span><span class="punct">,</span> <span class="number">72</span><span class="punct">])</span></pre></p> + + +<hr /> + + + <p><strong>simple line chart</strong> +<pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">70</span><span class="punct">,</span> <span class="number">20</span><span class="punct">])</span> +</pre></p> + + + <p>Generate the following url: http://chart.apis.google.com/chart?chs=300&#215;200&#38;chd=s:AiI9R&#38;cht=lc</p> + + + <p>Inserted in an image tag, it will look like that:</p> + + + <p><img src="http://chart.apis.google.com/chart?chs=300x200&#38;chd=s:AiI9R&#38;cht=lc" title="simple line chart" alt="simple line chart" /></p> + + + <p><strong>multiple line charts</strong> +<pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">0</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">70</span><span class="punct">,</span> <span class="number">20</span><span class="punct">],[</span><span class="number">41</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">80</span><span class="punct">,</span> <span class="number">50</span><span class="punct">]])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:AeH1P,fH9m" title="multiple lines chart" alt="multiple lines chart" /></p> + + + <p><strong>set line colors</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">0</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">70</span><span class="punct">,</span> <span class="number">20</span><span class="punct">],[</span><span class="number">41</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">80</span><span class="punct">,</span> <span class="number">50</span><span class="punct">]],</span> <span class="symbol">:line_colors</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">FF0000,00FF00</span><span class="punct">&quot;)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:AeH1P,fH9m&#38;chco=FF0000,00FF00" title="line colors" alt="line colors" /></p> + + + <p><a href="http://code.google.com/apis/chart/#chart_colors">more info about color settings</a></p> + + + <p><strong>sparkline chart</strong></p> + + + <p><pre class='syntax'> +<span class="ident">data</span> <span class="punct">=</span> <span class="punct">[</span><span class="number">27</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">27</span><span class="punct">,</span><span class="number">100</span><span class="punct">,</span><span class="number">31</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">36</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">39</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">31</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">28</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">100</span><span class="punct">,</span><span class="number">28</span><span class="punct">,</span><span class="number">27</span><span class="punct">,</span><span class="number">31</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">27</span><span class="punct">,</span><span class="number">27</span><span class="punct">,</span><span class="number">29</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">27</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">35</span><span class="punct">,</span><span class="number">33</span><span class="punct">,</span><span class="number">34</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">36</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">26</span><span class="punct">,</span><span class="number">37</span><span class="punct">,</span><span class="number">33</span><span class="punct">,</span><span class="number">33</span><span class="punct">,</span><span class="number">37</span><span class="punct">,</span><span class="number">37</span><span class="punct">,</span><span class="number">39</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">,</span><span class="number">25</span><span class="punct">]</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">sparkline</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="ident">data</span><span class="punct">,</span> <span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">120x40</span><span class="punct">',</span> <span class="symbol">:line_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">0077CC</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?chd=s:QPPPPQ9SPVPPXPSPPPPPPPRPP9RQSPQQRPQPPPPPVUUPPPVPPWUUWWXPPPP&#38;chco=0077CC&#38;chs=120x40&#38;cht=ls" title="sparline" alt="sparline" /></p> + + + <p>A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default.</p> + + + <p><strong>bar chart</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">])</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:9UGo" title="bars" alt="bars" /></p> + + + <p><strong>set the bar chart orientation</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="symbol">:orientation</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">horizontal</span><span class="punct">')</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=bhs&#38;chs=300x200&#38;chd=s:9UGo" title="bars" alt="bars" /></p> + + + <p><strong>multiple bars chart</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:9UGo,Uo9C" title="stacked multiple bars" alt="stacked multiple bars" /></p> + + + <p>The problem is that by default the bars are stacked, so we need to set the colors:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF0000,00FF00</span><span class="punct">')</span> +</pre></p> + + + <p>If you prefer you can use this other syntax:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">FF0000</span><span class="punct">',</span> <span class="punct">'</span><span class="string">00FF00</span><span class="punct">'])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:9UGo,Uo9C&#38;chco=FF0000,00FF00" title="colors" alt="colors" /></p> + + + <p>The problem now, is that we can&#8217;t see the first value of the second dataset since it&#8217;s lower than the first value of the first dataset. Let&#8217;s unstack the bars:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> + <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF0000,00FF00</span><span class="punct">',</span> + <span class="symbol">:stacked</span> <span class="punct">=&gt;</span> <span class="constant">false</span> <span class="punct">)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvg&#38;chs=300x200&#38;chd=s:9UGo,Uo9C&#38;chco=FF0000,00FF00" title="grouped bars" alt="grouped bars" /></p> + + + <p><strong>bar chart width and spacing</strong></p> + + + <p>A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash.</p> + + + <p>The Google <span class="caps">API</span> sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">25,6</span><span class="punct">')</span> <span class="comment"># width of 25, spacing of 6</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">25,6,12</span><span class="punct">')</span> <span class="comment"># width of 25, spacing of 6, group spacing of 12</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">25</span><span class="punct">,</span><span class="number">6</span><span class="punct">])</span> <span class="comment"># width of 25, spacing of 6</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="number">25</span><span class="punct">)</span> <span class="comment"># width of 25</span> +</pre></p> + + + <p>The hash lets you set these values directly, with the Google default values set for any options you don&#8217;t include:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:width</span> <span class="punct">=&gt;</span> <span class="number">19</span><span class="punct">})</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:spacing</span> <span class="punct">=&gt;</span> <span class="number">10</span><span class="punct">,</span> <span class="symbol">:group_spacing</span> <span class="punct">=&gt;</span> <span class="number">12</span><span class="punct">})</span> +</pre></p> + + + <p><strong>pie chart</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">pie</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">20</span><span class="punct">,</span> <span class="number">35</span><span class="punct">,</span> <span class="number">45</span><span class="punct">])</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=p&#38;chs=300x200&#38;chd=s:bv9" title="Pie Chart" alt="Pie Chart" /></p> + + + <p><strong>3D pie chart</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">pie_3d</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">20</span><span class="punct">,</span> <span class="number">35</span><span class="punct">,</span> <span class="number">45</span><span class="punct">])</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=p3&#38;chs=300x200&#38;chd=s:bv9" title="Pie Chart" alt="Pie Chart" /></p> + + + <p><strong>venn diagram</strong></p> + + + <p><a href="http://code.google.com/apis/chart/#venn">Google documentation</a></p> + + +Data set: + <ul> + <li>the first three values specify the relative sizes of three circles, A, B, and C</li> + <li>the fourth value specifies the area of A intersecting B</li> + <li>the fifth value specifies the area of B intersecting C</li> + <li>the sixth value specifies the area of C intersecting A</li> + <li>the seventh value specifies the area of A intersecting B intersecting C</li> + </ul> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">venn</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">80</span><span class="punct">,</span> <span class="number">60</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">])</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=v&#38;chs=300x200&#38;chd=s:9wkSSSG" title="Venn" alt="Venn" /></p> + + + <p><strong>scatter plot</strong></p> + + + <p><a href="http://code.google.com/apis/chart/#scatter_plot">Google Documentation</a></p> + + + <p>Supply two data sets, the first data set specifies x coordinates, the second set specifies y coordinates, the third set the data point size.</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">scatter</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">,</span> <span class="number">3</span><span class="punct">,</span> <span class="number">4</span><span class="punct">,</span> <span class="number">5</span><span class="punct">],</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">,</span> <span class="number">3</span><span class="punct">,</span> <span class="number">4</span> <span class="punct">,</span><span class="number">5</span><span class="punct">],</span> <span class="punct">[</span><span class="number">5</span><span class="punct">,</span> <span class="number">4</span><span class="punct">,</span> <span class="number">3</span><span class="punct">,</span> <span class="number">2</span><span class="punct">,</span> <span class="number">1</span><span class="punct">]])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=s&#38;chs=300x200&#38;chd=s:MYkw9,MYkw9,9wkYM" title="scatter" alt="scatter" /></p> + + + <p><strong>google-o-meter</strong></p> + + + <p><a href="http://code.google.com/apis/chart/#gom">Google Documentation</a></p> + + + <p>Supply a single label that will be what the arrow points to. It only supports a solid fill for the background.</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">meter</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">70</span><span class="punct">],</span> <span class="symbol">:label</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">Flavor</span><span class="punct">'])</span> +</pre></p> + + +<hr /> + + + <p><strong>set a chart title</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Recent Chart Sexyness</span><span class="punct">&quot;,</span> <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY9&#38;chtt=Recent+Chart+Sexyness" title="chart title" alt="chart title" /></p> + + + <p><strong>set the title size</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Recent Chart Sexyness</span><span class="punct">&quot;,</span> <span class="symbol">:title_size</span> <span class="punct">=&gt;</span> <span class="number">20</span><span class="punct">,</span> <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY9&#38;chtt=Recent+Chart+Sexyness&#38;chts=454545,20" title="title size" alt="title size" /></p> + + + <p><strong>set the title color</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Recent Chart Sexyness</span><span class="punct">&quot;,</span> <span class="symbol">:title_color</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF0000</span><span class="punct">',</span> <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY9&#38;chtt=Recent+Chart+Sexyness&#38;chts=FF0000" title="Title color" alt="Title color" /></p> + + + <p><strong>set the chart&#8217;s size</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Recent Chart Sexyness</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">],</span> + <span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">600x400</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=bvs&#38;chs=600x400&#38;chd=s:JSGM9MY9&#38;chtt=Recent+Chart+Sexyness" title="size" alt="size" /></p> + + + <p><strong>set the image background color</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">90</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">80</span><span class="punct">],</span> + <span class="symbol">:background</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF9994</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?chf=bg,s,FF9994&#38;cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY929w&#38;chtt=Matt's+Mojo" title="Background" alt="Background" /></p> + + + <p><strong>set the chart background color</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">90</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">80</span><span class="punct">],</span> + <span class="symbol">:background</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF9994</span><span class="punct">',</span> <span class="symbol">:chart_background</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">000000</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?chf=c,s,000000|bg,s,FF9994&#38;cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY929w&#38;chtt=Matt's+Mojo" title="chart background" alt="chart background" /></p> + + + <p><strong>Set bar/line colors</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">90</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">80</span><span class="punct">],</span> + <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">76A4FB</span><span class="punct">',</span> + <span class="symbol">:background</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">EEEEEE</span><span class="punct">',</span> <span class="symbol">:chart_background</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">CCCCCC</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?chf=c,s,CCCCCC|bg,s,EEEEEE&#38;cht=bvs&#38;chs=300x200&#38;chd=s:JSGM9MY929w&#38;chco=76A4FB&#38;chtt=Matt's+Mojo" title="bar colors" alt="bar colors" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">15</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">40</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">90</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">80</span><span class="punct">],</span> + <span class="symbol">:line_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">76A4FB</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:JSGM9MY929w&#38;chco=76A4FB&#38;chtt=Matt's+Mojo" title="line colors" alt="line colors" /></p> + + + <p><strong>legend / labels</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt vs Rob</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> + <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">FF0000,00FF00</span><span class="punct">',</span> + <span class="symbol">:stacked</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">,</span> <span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">400x200</span><span class="punct">',</span> + <span class="symbol">:legend</span> <span class="punct">=&gt;</span> <span class="punct">[&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Rob's Mojo</span><span class="punct">&quot;]</span> <span class="punct">)</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=bvg&#38;chdl=Matt's+Mojo|Rob's+Mojo&#38;chs=400x200&#38;chd=s:9UGo,Uo9C&#38;chco=FF0000,00FF00&#38;chtt=Matt+vs+Rob" title="legend" alt="legend" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Matt vs Rob</span><span class="punct">&quot;,</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> + <span class="symbol">:bar_colors</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">FF0000</span><span class="punct">','</span><span class="string">00FF00</span><span class="punct">'],</span> + <span class="symbol">:stacked</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">,</span> <span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">400x200</span><span class="punct">',</span> + <span class="symbol">:legend</span> <span class="punct">=&gt;</span> <span class="punct">[&quot;</span><span class="string">Matt's Mojo</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Rob's Mojo</span><span class="punct">&quot;]</span> <span class="punct">)</span> +</pre> +<img src="http://chart.apis.google.com/chart?cht=lc&#38;chdl=Matt's+Mojo|Rob's+Mojo&#38;chs=400x200&#38;chd=s:9UGo,Uo9C&#38;chco=FF0000,00FF00&#38;chtt=Matt+vs+Rob" title="line legend" alt="line legend" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">pie_3d</span><span class="punct">(</span><span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">ruby_fu</span><span class="punct">',</span> <span class="symbol">:size</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">400x200</span><span class="punct">',</span> + <span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">10</span><span class="punct">,</span> <span class="number">45</span><span class="punct">,</span> <span class="number">45</span><span class="punct">],</span> <span class="symbol">:labels</span> <span class="punct">=&gt;</span> <span class="punct">[&quot;</span><span class="string">DHH</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Rob</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Matt</span><span class="punct">&quot;]</span> <span class="punct">)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=p3&#38;chl=DHH|Rob|Matt&#38;chs=400x200&#38;chd=s:N99&#38;chtt=ruby_fu" title="labels" alt="labels" /></p> + + + <p><strong>Display axis labels</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">x,y,r</span><span class="punct">')</span> +</pre></p> + + + <p>or you can use the other syntax:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">x</span><span class="punct">','</span><span class="string">y</span><span class="punct">','</span><span class="string">r</span><span class="punct">'])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chxt=x,y,r&#38;chd=s:9UGoUo9C" title="axis with labels" alt="axis with labels" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">x</span><span class="punct">',</span> + <span class="symbol">:axis_labels</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">Jan|July|Jan|July|Jan</span><span class="punct">'])</span> +</pre></p> + + + <p>or you can use the other syntax:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">x</span><span class="punct">',</span> + <span class="symbol">:axis_labels</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">'])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chxl=0:|Jan|July|Jan|July|Jan&#38;chs=300x200&#38;chxt=x&#38;chd=s:9UGoUo9C" title="x labels" alt="x labels" /></p> + + + <p><strong>multiple axis labels</strong></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">x,r</span><span class="punct">',</span> + <span class="symbol">:axis_labels</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">Jan|July|Jan|July|Jan</span><span class="punct">',</span> <span class="punct">'</span><span class="string">2005|2006|2007</span><span class="punct">'])</span> +</pre></p> + + + <p>or</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">x,r</span><span class="punct">',</span> + <span class="symbol">:axis_labels</span> <span class="punct">=&gt;</span> <span class="punct">[['</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">'],</span> <span class="punct">['</span><span class="string">2005</span><span class="punct">','</span><span class="string">2006</span><span class="punct">','</span><span class="string">2007</span><span class="punct">']])</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chxl=0:|Jan|July|Jan|July|Jan|1:|2005|2006|2007&#38;chs=300x200&#38;chxt=x,r&#38;chd=s:9UGoUo9C" title="multiple axis labels" alt="multiple axis labels" /></p> + + + <p>(This syntax will probably be improved in the future)</p> + + + <p><strong>custom params</strong></p> + + + <p>I certainly didn&#8217;t cover the entire <span class="caps">API</span>, if you want to add your own params:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:custom</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&amp;chls=3,6,3|1,1,0</span><span class="punct">')</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&#38;chls=3,6,3|1,1,0" title="Custom" alt="Custom" /></p> + + +<hr /> + + + <p><strong>Save the chart as a file</strong></p> + + + <p>You might prefer to save the chart instead of using the url, not a problem:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">file</span><span class="punct">')</span> +</pre></p> + + + <p>You might want to specify the path and/or the filename used to save your chart:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">file</span><span class="punct">',</span> <span class="symbol">:filename</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">custom_filename.png</span><span class="punct">')</span> +</pre></p> + + + <p><strong>Insert as an image tag</strong></p> + + + <p>Because, I&#8217;m lazy, you can generate a full image tag, with support for standard html options.</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">')</span> +</pre></p> + + + <p><pre class='syntax'> +<span class="punct">&lt;</span><span class="ident">img</span> <span class="ident">src</span><span class="punct">=&quot;</span><span class="string">http://chart.apis.google.com/chart?chs=300x200&amp;amp;chd=s:A9&amp;amp;cht=lc</span><span class="punct">&quot;</span> <span class="ident">width</span><span class="punct">=&quot;</span><span class="string">300</span><span class="punct">&quot;</span> <span class="ident">height</span><span class="punct">=&quot;</span><span class="string">200</span><span class="punct">&quot;</span> <span class="ident">alt</span><span class="punct">=&quot;</span><span class="string">Google Chart</span><span class="punct">&quot;</span> <span class="punct">/&gt;</span> +</pre></p> + + + <p>Here are a few more examples:</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">')</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">',</span> <span class="symbol">:id</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">sexy</span><span class="punct">&quot;)</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">',</span> <span class="symbol">:class</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">chart</span><span class="punct">&quot;)</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">',</span> <span class="symbol">:alt</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Sexy Chart</span><span class="punct">&quot;)</span> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">image_tag</span><span class="punct">',</span> <span class="symbol">:title</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Sexy Chart</span><span class="punct">&quot;)</span> +</pre></p> + + + <p>Image dimensions will be automatically set based on your chart&#8217;s size.</p> + + +<hr /> + + + <p><strong>Encoding</strong></p> + + + <p>Google Chart <span class="caps">API</span> offers <a href="http://code.google.com/apis/chart/#chart_data">3 types of data encoding</a></p> + + + <ul> + <li>simple</li> + <li>text</li> + <li>extended</li> + </ul> + + + <p>By default this library uses the simple encoding, if you need a different type of encoding, you can change it really easily:</p> + + + <p>default / simple: chd=s:9UGoUo9C +<pre class='syntax'> + <span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]</span> <span class="punct">)</span> +</pre></p> + + + <p>extended: chd=e:..VVGZqqVVqq..CI +<pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:encoding</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">extended</span><span class="punct">'</span> <span class="punct">)</span> +</pre></p> + + + <p>text: chd=t:300,100,30,200,100,200,300,10 +<pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:encoding</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">text</span><span class="punct">'</span> <span class="punct">)</span> +</pre></p> + + + <p>(note that the text encoding doesn&#8217;t use a max value and therefore should be under 100)</p> + + + <p><strong>Max value</strong></p> + + + <p>Simple and extended encoding support the max value option.</p> + + + <p>The max value option is a simple way of scaling your graph. The data is converted in chart value with the highest chart value being the highest point on the graph. By default, the calculation is done for you. However you can specify your own maximum or not use a maximum at all.</p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]</span> <span class="punct">)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:9UGoUo9C" title="Title" alt="Title" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:max_value</span> <span class="punct">=&gt;</span> <span class="number">500</span> <span class="punct">)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:kMDYMYkB" title="max 500" alt="max 500" /></p> + + + <p><pre class='syntax'> +<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">20</span><span class="punct">,</span> <span class="number">10</span><span class="punct">,</span> <span class="number">14</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:max_value</span> <span class="punct">=&gt;</span> <span class="constant">false</span> <span class="punct">)</span> +</pre></p> + + + <p><img src="http://chart.apis.google.com/chart?cht=lc&#38;chs=300x200&#38;chd=s:_UeUKOeK" title="real size" alt="real size" /></p> + + + <h2>Repository</h2> + + + <p>The trunk repository is <code>http://github.com/mattetti/googlecharts/</code> for anonymous access.</p> + + + <h2>People reported using this gem</h2> + + +<div> + <img src="http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png" alt="github"/><br/> + <li><a href="http://github.com">http://github.com</a></li><br/> +</div> + +<div> + <img src="http://stafftool.com/images/masthead_screen.gif" alt="stafftool"/><br/> + <li><a href="http://stafftool.com/">Takeo(contributor)</a></li><br/> +</div> + +<div> + <img src="http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg" alt="graffletopia"/><br/> + <li><a href="http://graffletopia.com"> http://graffletopia.com Mokolabs(contributor)</a></li><br/> +</div> + +<div> + <img src="http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg" alt="gumgum"/><br/> + <li><a href="http://gumgum.com"> http://gumgum.com Mattetti(contributor)</a></li><br/> +</div> + +<div> + <img src="http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg" alt="gumgum"/><br/> + <li><a href="http://feedflix.com/"> http://feedflix.com/</a></li><br/> +</div> + + <h2>License</h2> + + + <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p> + + + <h2>Contact</h2> + + + <p>Comments are welcome. Send an email to <a href="mailto:[email protected]">Matt Aimonetti</a></p> + + + <h3>Contributors</h3> + + + <p><a href="http://github.com/dbgrandi">David Grandinetti</a> +<a href="http://github.com/takeo">Toby Sterrett</a> +<a href="http://github.com/mokolabs">Patrick Crowley</a></p> + <p class="coda"> + <a href="[email protected]">Matt Aimonetti</a>, 2nd July 2008<br> + Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a> + </p> +</div> + +<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> +</script> +<script type="text/javascript"> +_uacct = "UA-179809-11"; +urchinTracker(); +</script> + +</body> +</html> diff --git a/website/index.txt b/website/index.txt new file mode 100644 index 0000000..c6bf13f --- /dev/null +++ b/website/index.txt @@ -0,0 +1,570 @@ +h1. Googlecharts + +h2. &#x2192; 'Sexy Charts using Google API & Ruby' + + +h2. What + +A nice and simple wrapper for "Google Chart API":http://code.google.com/apis/chart/ +(Fully tested using RSpec, check the specs for more usage examples) + +h2. Installing + +This project is now hosted at "GitHub":http://github.com +If you never added "GitHub":http://github.com as a gem source, you will need to do the following: +<pre syntax="ruby">$ gem sources -a http://gems.github.com/</pre> (you only need to do this once) + +<pre syntax="ruby">$ sudo gem install mattetti-googlecharts</pre> + +or <pre syntax="ruby">$ sudo gem install googlecharts</pre> + +h2. The basics + +This gem supports the following types of charts: + +!http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld&chxt=x,y&chxl=0:|Mar|Apr|May|June|July|1:||50+Kb(Line)! Gchart.line() + +!http://chart.apis.google.com/chart?cht=lxy&chs=200x125&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5(line_xy)! Gchart.line_xy() + +!http://chart.apis.google.com/chart?cht=s&chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&chxt=x,y&chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&chs=200x125(scatter)! Gchart.scatter() + +!http://chart.apis.google.com/chart?cht=bvg&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00(bar)! Gchart.bar() + +!http://chart.apis.google.com/chart?cht=v&chs=200x100&chd=t:100,80,60,30,30,30,10(venn)! Gchart.venn() + +!http://chart.apis.google.com/chart?cht=p&chd=s:world5&chs=200x125&chl=A|B|C|D|E|Fe(pie)! Gchart.pie() + +!http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=200x100&chl=A|B|C|D(pie_3d)! Gchart.pie_3d() + +!http://chart.apis.google.com/chart?chs=100x20&cht=ls&chco=0077CC&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=t:27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25(sparkline)!Gchart.sparkline() + +!http://chart.apis.google.com/chart?chs=225x125&cht=gom&chd=t:70&chl=Flavor(google-o-meter)! Gchart.meter() + +h2. Demonstration of usage + +install: + +<code>sudo gem install mattetti-googlecharts</code> + +or use rubyforge: + +<code>sudo gem install googlecharts</code> + +require: +<pre syntax="ruby">require 'gchart'</pre> + +<pre syntax="ruby"> +Gchart.line(:size => '200x300', + :title => "example title", + :bg => 'efefef', + :legend => ['first data set label', 'second data set label'], + :data => [10, 30, 120, 45, 72])</pre> + +--- + +*simple line chart* +<pre syntax="ruby"> +Gchart.line(:data => [0, 40, 10, 70, 20]) +</pre> + +Generate the following url: http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc + +Inserted in an image tag, it will look like that: + +!http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc(simple line chart)! + +*multiple line charts* +<pre syntax="ruby"> +Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]]) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m(multiple lines chart)! + +*set line colors* + +<pre syntax="ruby"> +Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :line_colors => "FF0000,00FF00") +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m&chco=FF0000,00FF00(line colors)! + +"more info about color settings":http://code.google.com/apis/chart/#chart_colors + +*sparkline chart* + +<pre syntax="ruby"> +data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25] +Gchart.sparkline(:data => data, :size => '120x40', :line_colors => '0077CC') +</pre> + +!http://chart.apis.google.com/chart?chd=s:QPPPPQ9SPVPPXPSPPPPPPPRPP9RQSPQQRPQPPPPPVUUPPPVPPWUUWWXPPPP&chco=0077CC&chs=120x40&cht=ls(sparline)! + +A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default. + +*bar chart* + +<pre syntax="ruby"> +Gchart.bar(:data => [300, 100, 30, 200]) +</pre> +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo(bars)! + +*set the bar chart orientation* + +<pre syntax="ruby"> +Gchart.bar(:data => [300, 100, 30, 200], :orientation => 'horizontal') +</pre> +!http://chart.apis.google.com/chart?cht=bhs&chs=300x200&chd=s:9UGo(bars)! + +*multiple bars chart* + +<pre syntax="ruby"> +Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]]) +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C(stacked multiple bars)! + +The problem is that by default the bars are stacked, so we need to set the colors: + +<pre syntax="ruby"> +Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => 'FF0000,00FF00') +</pre> + +If you prefer you can use this other syntax: + +<pre syntax="ruby"> +Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => ['FF0000', '00FF00']) +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(colors)! + +The problem now, is that we can't see the first value of the second dataset since it's lower than the first value of the first dataset. Let's unstack the bars: + +<pre syntax="ruby"> +Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], + :bar_colors => 'FF0000,00FF00', + :stacked => false ) +</pre> + +!http://chart.apis.google.com/chart?cht=bvg&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(grouped bars)! + +*bar chart width and spacing* + +A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash. + +The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order: + +<pre syntax="ruby"> +Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6 +Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12 +Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6 +Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25 +</pre> + +The hash lets you set these values directly, with the Google default values set for any options you don't include: + +<pre syntax="ruby"> +Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19}) +Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12}) +</pre> + + +*pie chart* + +<pre syntax="ruby"> +Gchart.pie(:data => [20, 35, 45]) +</pre> +!http://chart.apis.google.com/chart?cht=p&chs=300x200&chd=s:bv9(Pie Chart)! + +*3D pie chart* + +<pre syntax="ruby"> +Gchart.pie_3d(:data => [20, 35, 45]) +</pre> +!http://chart.apis.google.com/chart?cht=p3&chs=300x200&chd=s:bv9(Pie Chart)! + +*venn diagram* + +"Google documentation":http://code.google.com/apis/chart/#venn + +Data set: +* the first three values specify the relative sizes of three circles, A, B, and C +* the fourth value specifies the area of A intersecting B +* the fifth value specifies the area of B intersecting C +* the sixth value specifies the area of C intersecting A +* the seventh value specifies the area of A intersecting B intersecting C + +<pre syntax="ruby"> +Gchart.venn(:data => [100, 80, 60, 30, 30, 30, 10]) +</pre> +!http://chart.apis.google.com/chart?cht=v&chs=300x200&chd=s:9wkSSSG(Venn)! + +*scatter plot* + +"Google Documentation":http://code.google.com/apis/chart/#scatter_plot + +Supply two data sets, the first data set specifies x coordinates, the second set specifies y coordinates, the third set the data point size. + +<pre syntax="ruby"> +Gchart.scatter(:data => [[1, 2, 3, 4, 5], [1, 2, 3, 4 ,5], [5, 4, 3, 2, 1]]) +</pre> + +!http://chart.apis.google.com/chart?cht=s&chs=300x200&chd=s:MYkw9,MYkw9,9wkYM(scatter)! + +*google-o-meter* + +"Google Documentation":http://code.google.com/apis/chart/#gom + +Supply a single label that will be what the arrow points to. It only supports a solid fill for the background. + +<pre syntax="ruby"> + Gchart.meter(:data => [70], :label => ['Flavor']) +</pre> + + +*Chart themes* + +Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from "Gruff": http://github.com/topfunky/gruff/tree/master ) + +<pre syntax="ruby"> + Gchart.line( + :theme => :keynote, + :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]], + :title => 'keynote' + ) +</pre> + +* keynote + +!http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000! + +* thirty7signals + +!http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF! + +* pastel + +!http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo! + +* greyscale + +!http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo! + + +You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml + +Load your theme(s): + +<pre syntax="ruby"> + Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml") +</pre> + +And use the standard method signature to use your own theme: + +<pre syntax="ruby"> + Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale') +</pre> + + +--- + +*set a chart title* + +<pre syntax="ruby"> +Gchart.bar(:title => "Recent Chart Sexyness", :data => [15, 30, 10, 20, 100, 20, 40, 100]) +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(chart title)! + +*set the title size* + +<pre syntax="ruby"> +Gchart.bar(:title => "Recent Chart Sexyness", :title_size => 20, :data => [15, 30, 10, 20, 100, 20, 40, 100]) +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=454545,20(title size)! + +*set the title color* + +<pre syntax="ruby"> +Gchart.bar(:title => "Recent Chart Sexyness", :title_color => 'FF0000', :data => [15, 30, 10, 20, 100, 20, 40, 100]) +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=FF0000(Title color)! + +*set the chart's size* + +<pre syntax="ruby"> +Gchart.bar(:title => "Recent Chart Sexyness", + :data => [15, 30, 10, 20, 100, 20, 40, 100], + :size => '600x400') +</pre> + +!http://chart.apis.google.com/chart?cht=bvs&chs=600x400&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(size)! + +*set the image background color* + +<pre syntax="ruby"> +Gchart.bar(:title => "Matt's Mojo", + :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], + :background => 'FF9994') +</pre> + +!http://chart.apis.google.com/chart?chf=bg,s,FF9994&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(Background)! + +*set the chart background color* + +<pre syntax="ruby"> +Gchart.bar(:title => "Matt's Mojo", + :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], + :background => 'FF9994', :chart_background => '000000') +</pre> + +!http://chart.apis.google.com/chart?chf=c,s,000000|bg,s,FF9994&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(chart background)! + +*Set bar/line colors* + +<pre syntax="ruby"> +Gchart.bar(:title => "Matt's Mojo", + :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], + :bar_colors => '76A4FB', + :background => 'EEEEEE', :chart_background => 'CCCCCC') +</pre> + +!http://chart.apis.google.com/chart?chf=c,s,CCCCCC|bg,s,EEEEEE&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chco=76A4FB&chtt=Matt's+Mojo(bar colors)! + +<pre syntax="ruby"> +Gchart.line(:title => "Matt's Mojo", + :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80], + :line_colors => '76A4FB') +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:JSGM9MY929w&chco=76A4FB&chtt=Matt's+Mojo(line colors)! + +*legend / labels* + +<pre syntax="ruby"> +Gchart.bar(:title => "Matt vs Rob", + :data => [[300, 100, 30, 200], [100, 200, 300, 10]], + :bar_colors => 'FF0000,00FF00', + :stacked => false, :size => '400x200', + :legend => ["Matt's Mojo", "Rob's Mojo"] ) +</pre> +!http://chart.apis.google.com/chart?cht=bvg&chdl=Matt's+Mojo|Rob's+Mojo&chs=400x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00&chtt=Matt+vs+Rob(legend)! + +<pre syntax="ruby"> +Gchart.line(:title => "Matt vs Rob", + :data => [[300, 100, 30, 200], [100, 200, 300, 10]], + :bar_colors => ['FF0000','00FF00'], + :stacked => false, :size => '400x200', + :legend => ["Matt's Mojo", "Rob's Mojo"] ) +</pre> +!http://chart.apis.google.com/chart?cht=lc&chdl=Matt's+Mojo|Rob's+Mojo&chs=400x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00&chtt=Matt+vs+Rob(line legend)! + + +<pre syntax="ruby"> +Gchart.pie_3d(:title => 'ruby_fu', :size => '400x200', + :data => [10, 45, 45], :labels => ["DHH", "Rob", "Matt"] ) +</pre> + +!http://chart.apis.google.com/chart?cht=p3&chl=DHH|Rob|Matt&chs=400x200&chd=s:N99&chtt=ruby_fu(labels)! + +*Display axis labels* + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,y,r') +</pre> + +or you can use the other syntax: + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => ['x','y','r']) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chxt=x,y,r&chd=s:9UGoUo9C(axis with labels)! + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x', + :axis_labels => ['Jan|July|Jan|July|Jan']) +</pre> + +or you can use the other syntax: + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x', + :axis_labels => ['Jan','July','Jan','July','Jan']) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan&chs=300x200&chxt=x&chd=s:9UGoUo9C(x labels)! + +*multiple axis labels* + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r', + :axis_labels => ['Jan|July|Jan|July|Jan', '2005|2006|2007']) +</pre> + +or + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r', + :axis_labels => [['Jan','July','Jan','July','Jan'], ['2005','2006','2007']]) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan|1:|2005|2006|2007&chs=300x200&chxt=x,r&chd=s:9UGoUo9C(multiple axis labels)! + +(This syntax will probably be improved in the future) + +*custom params* + +I certainly didn't cover the entire API, if you want to add your own params: + +<pre syntax="ruby"> +Gchart.line(:custom => 'chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0') +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0(Custom)! + +--- + +*Save the chart as a file* + +You might prefer to save the chart instead of using the url, not a problem: + +<pre syntax="ruby"> +Gchart.line(:data => [0, 26], :format => 'file') +</pre> + +You might want to specify the path and/or the filename used to save your chart: + +<pre syntax="ruby"> +Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_filename.png') +</pre> + +*Insert as an image tag* + +Because, I'm lazy, you can generate a full image tag, with support for standard html options. + +<pre syntax="ruby"> +Gchart.line(:data => [0, 26], :format => 'image_tag') +</pre> + +<pre syntax="ruby"> +<img src="http://chart.apis.google.com/chart?chs=300x200&amp;chd=s:A9&amp;cht=lc" width="300" height="200" alt="Google Chart" /> +</pre> + +Here are a few more examples: + +<pre syntax="ruby"> +Gchart.line(:data => [0, 26], :format => 'image_tag') +Gchart.line(:data => [0, 26], :format => 'image_tag', :id => "sexy") +Gchart.line(:data => [0, 26], :format => 'image_tag', :class => "chart") +Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => "Sexy Chart") +Gchart.line(:data => [0, 26], :format => 'image_tag', :title => "Sexy Chart") +</pre> + +Image dimensions will be automatically set based on your chart's size. + +--- + +*Encoding* + +Google Chart API offers "3 types of data encoding":http://code.google.com/apis/chart/#chart_data + + * simple + * text + * extended + +By default this library uses the simple encoding, if you need a different type of encoding, you can change it really easily: + +default / simple: chd=s:9UGoUo9C +<pre syntax="ruby"> + Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10] ) +</pre> + +extended: chd=e:..VVGZqqVVqq..CI +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'extended' ) +</pre> + +text: chd=t:300,100,30,200,100,200,300,10 +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'text' ) +</pre> + +(note that the text encoding doesn't use a max value and therefore should be under 100) + +*Max value* + +Simple and extended encoding support the max value option. + +The max value option is a simple way of scaling your graph. The data is converted in chart value with the highest chart value being the highest point on the graph. By default, the calculation is done for you. However you can specify your own maximum or not use a maximum at all. + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10] ) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C(Title)! + +<pre syntax="ruby"> +Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :max_value => 500 ) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:kMDYMYkB(max 500)! + +<pre syntax="ruby"> +Gchart.line(:data => [100, 20, 30, 20, 10, 14, 30, 10], :max_value => false ) +</pre> + +!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:_UeUKOeK(real size)! + + +h2. Repository + +The trunk repository is <code>http://github.com/mattetti/googlecharts/</code> for anonymous access. + +h2. People reported using this gem + + + <div> + <img src="http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png" alt="github"/><br/> + <li><a href="http://github.com">http://github.com</a></li><br/> + </div> + + <div> + <img src="http://stafftool.com/images/masthead_screen.gif" alt="stafftool"/><br/> + <li><a href="http://stafftool.com/">Takeo(contributor)</a></li><br/> + </div> + + <div> + <img src="http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg" alt="graffletopia"/><br/> + <li><a href="http://graffletopia.com"> http://graffletopia.com Mokolabs(contributor)</a></li><br/> + </div> + + <div> + <img src="http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg" alt="gumgum"/><br/> + <li><a href="http://gumgum.com"> http://gumgum.com Mattetti(contributor)</a></li><br/> + </div> + + <div> + <img src="http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg" alt="feedflix"/><br/> + <li><a href="http://feedflix.com/"> http://feedflix.com/</a></li><br/> + </div> + + <div> + <li><a href="http://www.csuchico.edu/"> California State University, Chico</a></li><br/> + </div> + + +h2. License + +This code is free to use under the terms of the MIT license. + +h2. Contact + +Comments are welcome. Send an email to "Matt Aimonetti":mailto:[email protected] + +h3. Contributors + +"David Grandinetti":http://github.com/dbgrandi +"Toby Sterrett":http://github.com/takeo +"Patrick Crowley":http://github.com/mokolabs \ No newline at end of file diff --git a/website/javascripts/rounded_corners_lite.inc.js b/website/javascripts/rounded_corners_lite.inc.js new file mode 100644 index 0000000..afc3ea3 --- /dev/null +++ b/website/javascripts/rounded_corners_lite.inc.js @@ -0,0 +1,285 @@ + + /**************************************************************** + * * + * curvyCorners * + * ------------ * + * * + * This script generates rounded corners for your divs. * + * * + * Version 1.2.9 * + * Copyright (c) 2006 Cameron Cooke * + * By: Cameron Cooke and Tim Hutchison. * + * * + * * + * Website: http://www.curvycorners.net * + * Email: [email protected] * + * Forum: http://www.curvycorners.net/forum/ * + * * + * * + * This library is free software; you can redistribute * + * it and/or modify it under the terms of the GNU * + * Lesser General Public License as published by the * + * Free Software Foundation; either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will * + * be useful, but WITHOUT ANY WARRANTY; without even the * + * implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU Lesser General Public * + * License for more details. * + * * + * You should have received a copy of the GNU Lesser * + * General Public License along with this library; * + * Inc., 59 Temple Place, Suite 330, Boston, * + * MA 02111-1307 USA * + * * + ****************************************************************/ + +var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1; var isMoz = document.implementation && document.implementation.createDocument; var isSafari = ((navigator.userAgent.toLowerCase().indexOf('safari')!=-1)&&(navigator.userAgent.toLowerCase().indexOf('mac')!=-1))?true:false; function curvyCorners() +{ if(typeof(arguments[0]) != "object") throw newCurvyError("First parameter of curvyCorners() must be an object."); if(typeof(arguments[1]) != "object" && typeof(arguments[1]) != "string") throw newCurvyError("Second parameter of curvyCorners() must be an object or a class name."); if(typeof(arguments[1]) == "string") +{ var startIndex = 0; var boxCol = getElementsByClass(arguments[1]);} +else +{ var startIndex = 1; var boxCol = arguments;} +var curvyCornersCol = new Array(); if(arguments[0].validTags) +var validElements = arguments[0].validTags; else +var validElements = ["div"]; for(var i = startIndex, j = boxCol.length; i < j; i++) +{ var currentTag = boxCol[i].tagName.toLowerCase(); if(inArray(validElements, currentTag) !== false) +{ curvyCornersCol[curvyCornersCol.length] = new curvyObject(arguments[0], boxCol[i]);} +} +this.objects = curvyCornersCol; this.applyCornersToAll = function() +{ for(var x = 0, k = this.objects.length; x < k; x++) +{ this.objects[x].applyCorners();} +} +} +function curvyObject() +{ this.box = arguments[1]; this.settings = arguments[0]; this.topContainer = null; this.bottomContainer = null; this.masterCorners = new Array(); this.contentDIV = null; var boxHeight = get_style(this.box, "height", "height"); var boxWidth = get_style(this.box, "width", "width"); var borderWidth = get_style(this.box, "borderTopWidth", "border-top-width"); var borderColour = get_style(this.box, "borderTopColor", "border-top-color"); var boxColour = get_style(this.box, "backgroundColor", "background-color"); var backgroundImage = get_style(this.box, "backgroundImage", "background-image"); var boxPosition = get_style(this.box, "position", "position"); var boxPadding = get_style(this.box, "paddingTop", "padding-top"); this.boxHeight = parseInt(((boxHeight != "" && boxHeight != "auto" && boxHeight.indexOf("%") == -1)? boxHeight.substring(0, boxHeight.indexOf("px")) : this.box.scrollHeight)); this.boxWidth = parseInt(((boxWidth != "" && boxWidth != "auto" && boxWidth.indexOf("%") == -1)? boxWidth.substring(0, boxWidth.indexOf("px")) : this.box.scrollWidth)); this.borderWidth = parseInt(((borderWidth != "" && borderWidth.indexOf("px") !== -1)? borderWidth.slice(0, borderWidth.indexOf("px")) : 0)); this.boxColour = format_colour(boxColour); this.boxPadding = parseInt(((boxPadding != "" && boxPadding.indexOf("px") !== -1)? boxPadding.slice(0, boxPadding.indexOf("px")) : 0)); this.borderColour = format_colour(borderColour); this.borderString = this.borderWidth + "px" + " solid " + this.borderColour; this.backgroundImage = ((backgroundImage != "none")? backgroundImage : ""); this.boxContent = this.box.innerHTML; if(boxPosition != "absolute") this.box.style.position = "relative"; this.box.style.padding = "0px"; if(isIE && boxWidth == "auto" && boxHeight == "auto") this.box.style.width = "100%"; if(this.settings.autoPad == true && this.boxPadding > 0) +this.box.innerHTML = ""; this.applyCorners = function() +{ for(var t = 0; t < 2; t++) +{ switch(t) +{ case 0: +if(this.settings.tl || this.settings.tr) +{ var newMainContainer = document.createElement("DIV"); newMainContainer.style.width = "100%"; newMainContainer.style.fontSize = "1px"; newMainContainer.style.overflow = "hidden"; newMainContainer.style.position = "absolute"; newMainContainer.style.paddingLeft = this.borderWidth + "px"; newMainContainer.style.paddingRight = this.borderWidth + "px"; var topMaxRadius = Math.max(this.settings.tl ? this.settings.tl.radius : 0, this.settings.tr ? this.settings.tr.radius : 0); newMainContainer.style.height = topMaxRadius + "px"; newMainContainer.style.top = 0 - topMaxRadius + "px"; newMainContainer.style.left = 0 - this.borderWidth + "px"; this.topContainer = this.box.appendChild(newMainContainer);} +break; case 1: +if(this.settings.bl || this.settings.br) +{ var newMainContainer = document.createElement("DIV"); newMainContainer.style.width = "100%"; newMainContainer.style.fontSize = "1px"; newMainContainer.style.overflow = "hidden"; newMainContainer.style.position = "absolute"; newMainContainer.style.paddingLeft = this.borderWidth + "px"; newMainContainer.style.paddingRight = this.borderWidth + "px"; var botMaxRadius = Math.max(this.settings.bl ? this.settings.bl.radius : 0, this.settings.br ? this.settings.br.radius : 0); newMainContainer.style.height = botMaxRadius + "px"; newMainContainer.style.bottom = 0 - botMaxRadius + "px"; newMainContainer.style.left = 0 - this.borderWidth + "px"; this.bottomContainer = this.box.appendChild(newMainContainer);} +break;} +} +if(this.topContainer) this.box.style.borderTopWidth = "0px"; if(this.bottomContainer) this.box.style.borderBottomWidth = "0px"; var corners = ["tr", "tl", "br", "bl"]; for(var i in corners) +{ if(i > -1 < 4) +{ var cc = corners[i]; if(!this.settings[cc]) +{ if(((cc == "tr" || cc == "tl") && this.topContainer != null) || ((cc == "br" || cc == "bl") && this.bottomContainer != null)) +{ var newCorner = document.createElement("DIV"); newCorner.style.position = "relative"; newCorner.style.fontSize = "1px"; newCorner.style.overflow = "hidden"; if(this.backgroundImage == "") +newCorner.style.backgroundColor = this.boxColour; else +newCorner.style.backgroundImage = this.backgroundImage; switch(cc) +{ case "tl": +newCorner.style.height = topMaxRadius - this.borderWidth + "px"; newCorner.style.marginRight = this.settings.tr.radius - (this.borderWidth*2) + "px"; newCorner.style.borderLeft = this.borderString; newCorner.style.borderTop = this.borderString; newCorner.style.left = -this.borderWidth + "px"; break; case "tr": +newCorner.style.height = topMaxRadius - this.borderWidth + "px"; newCorner.style.marginLeft = this.settings.tl.radius - (this.borderWidth*2) + "px"; newCorner.style.borderRight = this.borderString; newCorner.style.borderTop = this.borderString; newCorner.style.backgroundPosition = "-" + (topMaxRadius + this.borderWidth) + "px 0px"; newCorner.style.left = this.borderWidth + "px"; break; case "bl": +newCorner.style.height = botMaxRadius - this.borderWidth + "px"; newCorner.style.marginRight = this.settings.br.radius - (this.borderWidth*2) + "px"; newCorner.style.borderLeft = this.borderString; newCorner.style.borderBottom = this.borderString; newCorner.style.left = -this.borderWidth + "px"; newCorner.style.backgroundPosition = "-" + (this.borderWidth) + "px -" + (this.boxHeight + (botMaxRadius + this.borderWidth)) + "px"; break; case "br": +newCorner.style.height = botMaxRadius - this.borderWidth + "px"; newCorner.style.marginLeft = this.settings.bl.radius - (this.borderWidth*2) + "px"; newCorner.style.borderRight = this.borderString; newCorner.style.borderBottom = this.borderString; newCorner.style.left = this.borderWidth + "px" +newCorner.style.backgroundPosition = "-" + (botMaxRadius + this.borderWidth) + "px -" + (this.boxHeight + (botMaxRadius + this.borderWidth)) + "px"; break;} +} +} +else +{ if(this.masterCorners[this.settings[cc].radius]) +{ var newCorner = this.masterCorners[this.settings[cc].radius].cloneNode(true);} +else +{ var newCorner = document.createElement("DIV"); newCorner.style.height = this.settings[cc].radius + "px"; newCorner.style.width = this.settings[cc].radius + "px"; newCorner.style.position = "absolute"; newCorner.style.fontSize = "1px"; newCorner.style.overflow = "hidden"; var borderRadius = parseInt(this.settings[cc].radius - this.borderWidth); for(var intx = 0, j = this.settings[cc].radius; intx < j; intx++) +{ if((intx +1) >= borderRadius) +var y1 = -1; else +var y1 = (Math.floor(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow((intx+1), 2))) - 1); if(borderRadius != j) +{ if((intx) >= borderRadius) +var y2 = -1; else +var y2 = Math.ceil(Math.sqrt(Math.pow(borderRadius,2) - Math.pow(intx, 2))); if((intx+1) >= j) +var y3 = -1; else +var y3 = (Math.floor(Math.sqrt(Math.pow(j ,2) - Math.pow((intx+1), 2))) - 1);} +if((intx) >= j) +var y4 = -1; else +var y4 = Math.ceil(Math.sqrt(Math.pow(j ,2) - Math.pow(intx, 2))); if(y1 > -1) this.drawPixel(intx, 0, this.boxColour, 100, (y1+1), newCorner, -1, this.settings[cc].radius); if(borderRadius != j) +{ for(var inty = (y1 + 1); inty < y2; inty++) +{ if(this.settings.antiAlias) +{ if(this.backgroundImage != "") +{ var borderFract = (pixelFraction(intx, inty, borderRadius) * 100); if(borderFract < 30) +{ this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, 0, this.settings[cc].radius);} +else +{ this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, -1, this.settings[cc].radius);} +} +else +{ var pixelcolour = BlendColour(this.boxColour, this.borderColour, pixelFraction(intx, inty, borderRadius)); this.drawPixel(intx, inty, pixelcolour, 100, 1, newCorner, 0, this.settings[cc].radius, cc);} +} +} +if(this.settings.antiAlias) +{ if(y3 >= y2) +{ if (y2 == -1) y2 = 0; this.drawPixel(intx, y2, this.borderColour, 100, (y3 - y2 + 1), newCorner, 0, 0);} +} +else +{ if(y3 >= y1) +{ this.drawPixel(intx, (y1 + 1), this.borderColour, 100, (y3 - y1), newCorner, 0, 0);} +} +var outsideColour = this.borderColour;} +else +{ var outsideColour = this.boxColour; var y3 = y1;} +if(this.settings.antiAlias) +{ for(var inty = (y3 + 1); inty < y4; inty++) +{ this.drawPixel(intx, inty, outsideColour, (pixelFraction(intx, inty , j) * 100), 1, newCorner, ((this.borderWidth > 0)? 0 : -1), this.settings[cc].radius);} +} +} +this.masterCorners[this.settings[cc].radius] = newCorner.cloneNode(true);} +if(cc != "br") +{ for(var t = 0, k = newCorner.childNodes.length; t < k; t++) +{ var pixelBar = newCorner.childNodes[t]; var pixelBarTop = parseInt(pixelBar.style.top.substring(0, pixelBar.style.top.indexOf("px"))); var pixelBarLeft = parseInt(pixelBar.style.left.substring(0, pixelBar.style.left.indexOf("px"))); var pixelBarHeight = parseInt(pixelBar.style.height.substring(0, pixelBar.style.height.indexOf("px"))); if(cc == "tl" || cc == "bl"){ pixelBar.style.left = this.settings[cc].radius -pixelBarLeft -1 + "px";} +if(cc == "tr" || cc == "tl"){ pixelBar.style.top = this.settings[cc].radius -pixelBarHeight -pixelBarTop + "px";} +switch(cc) +{ case "tr": +pixelBar.style.backgroundPosition = "-" + Math.abs((this.boxWidth - this.settings[cc].radius + this.borderWidth) + pixelBarLeft) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px"; break; case "tl": +pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px"; break; case "bl": +pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) + "px -" + Math.abs((this.boxHeight + this.settings[cc].radius + pixelBarTop) -this.borderWidth) + "px"; break;} +} +} +} +if(newCorner) +{ switch(cc) +{ case "tl": +if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "tr": +if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "bl": +if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break; case "br": +if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break;} +} +} +} +var radiusDiff = new Array(); radiusDiff["t"] = Math.abs(this.settings.tl.radius - this.settings.tr.radius) +radiusDiff["b"] = Math.abs(this.settings.bl.radius - this.settings.br.radius); for(z in radiusDiff) +{ if(z == "t" || z == "b") +{ if(radiusDiff[z]) +{ var smallerCornerType = ((this.settings[z + "l"].radius < this.settings[z + "r"].radius)? z +"l" : z +"r"); var newFiller = document.createElement("DIV"); newFiller.style.height = radiusDiff[z] + "px"; newFiller.style.width = this.settings[smallerCornerType].radius+ "px" +newFiller.style.position = "absolute"; newFiller.style.fontSize = "1px"; newFiller.style.overflow = "hidden"; newFiller.style.backgroundColor = this.boxColour; switch(smallerCornerType) +{ case "tl": +newFiller.style.bottom = "0px"; newFiller.style.left = "0px"; newFiller.style.borderLeft = this.borderString; this.topContainer.appendChild(newFiller); break; case "tr": +newFiller.style.bottom = "0px"; newFiller.style.right = "0px"; newFiller.style.borderRight = this.borderString; this.topContainer.appendChild(newFiller); break; case "bl": +newFiller.style.top = "0px"; newFiller.style.left = "0px"; newFiller.style.borderLeft = this.borderString; this.bottomContainer.appendChild(newFiller); break; case "br": +newFiller.style.top = "0px"; newFiller.style.right = "0px"; newFiller.style.borderRight = this.borderString; this.bottomContainer.appendChild(newFiller); break;} +} +var newFillerBar = document.createElement("DIV"); newFillerBar.style.position = "relative"; newFillerBar.style.fontSize = "1px"; newFillerBar.style.overflow = "hidden"; newFillerBar.style.backgroundColor = this.boxColour; newFillerBar.style.backgroundImage = this.backgroundImage; switch(z) +{ case "t": +if(this.topContainer) +{ if(this.settings.tl.radius && this.settings.tr.radius) +{ newFillerBar.style.height = topMaxRadius - this.borderWidth + "px"; newFillerBar.style.marginLeft = this.settings.tl.radius - this.borderWidth + "px"; newFillerBar.style.marginRight = this.settings.tr.radius - this.borderWidth + "px"; newFillerBar.style.borderTop = this.borderString; if(this.backgroundImage != "") +newFillerBar.style.backgroundPosition = "-" + (topMaxRadius + this.borderWidth) + "px 0px"; this.topContainer.appendChild(newFillerBar);} +this.box.style.backgroundPosition = "0px -" + (topMaxRadius - this.borderWidth) + "px";} +break; case "b": +if(this.bottomContainer) +{ if(this.settings.bl.radius && this.settings.br.radius) +{ newFillerBar.style.height = botMaxRadius - this.borderWidth + "px"; newFillerBar.style.marginLeft = this.settings.bl.radius - this.borderWidth + "px"; newFillerBar.style.marginRight = this.settings.br.radius - this.borderWidth + "px"; newFillerBar.style.borderBottom = this.borderString; if(this.backgroundImage != "") +newFillerBar.style.backgroundPosition = "-" + (botMaxRadius + this.borderWidth) + "px -" + (this.boxHeight + (topMaxRadius + this.borderWidth)) + "px"; this.bottomContainer.appendChild(newFillerBar);} +} +break;} +} +} +if(this.settings.autoPad == true && this.boxPadding > 0) +{ var contentContainer = document.createElement("DIV"); contentContainer.style.position = "relative"; contentContainer.innerHTML = this.boxContent; contentContainer.className = "autoPadDiv"; var topPadding = Math.abs(topMaxRadius - this.boxPadding); var botPadding = Math.abs(botMaxRadius - this.boxPadding); if(topMaxRadius < this.boxPadding) +contentContainer.style.paddingTop = topPadding + "px"; if(botMaxRadius < this.boxPadding) +contentContainer.style.paddingBottom = botMaxRadius + "px"; contentContainer.style.paddingLeft = this.boxPadding + "px"; contentContainer.style.paddingRight = this.boxPadding + "px"; this.contentDIV = this.box.appendChild(contentContainer);} +} +this.drawPixel = function(intx, inty, colour, transAmount, height, newCorner, image, cornerRadius) +{ var pixel = document.createElement("DIV"); pixel.style.height = height + "px"; pixel.style.width = "1px"; pixel.style.position = "absolute"; pixel.style.fontSize = "1px"; pixel.style.overflow = "hidden"; var topMaxRadius = Math.max(this.settings["tr"].radius, this.settings["tl"].radius); if(image == -1 && this.backgroundImage != "") +{ pixel.style.backgroundImage = this.backgroundImage; pixel.style.backgroundPosition = "-" + (this.boxWidth - (cornerRadius - intx) + this.borderWidth) + "px -" + ((this.boxHeight + topMaxRadius + inty) -this.borderWidth) + "px";} +else +{ pixel.style.backgroundColor = colour;} +if (transAmount != 100) +setOpacity(pixel, transAmount); pixel.style.top = inty + "px"; pixel.style.left = intx + "px"; newCorner.appendChild(pixel);} +} +function insertAfter(parent, node, referenceNode) +{ parent.insertBefore(node, referenceNode.nextSibling);} +function BlendColour(Col1, Col2, Col1Fraction) +{ var red1 = parseInt(Col1.substr(1,2),16); var green1 = parseInt(Col1.substr(3,2),16); var blue1 = parseInt(Col1.substr(5,2),16); var red2 = parseInt(Col2.substr(1,2),16); var green2 = parseInt(Col2.substr(3,2),16); var blue2 = parseInt(Col2.substr(5,2),16); if(Col1Fraction > 1 || Col1Fraction < 0) Col1Fraction = 1; var endRed = Math.round((red1 * Col1Fraction) + (red2 * (1 - Col1Fraction))); if(endRed > 255) endRed = 255; if(endRed < 0) endRed = 0; var endGreen = Math.round((green1 * Col1Fraction) + (green2 * (1 - Col1Fraction))); if(endGreen > 255) endGreen = 255; if(endGreen < 0) endGreen = 0; var endBlue = Math.round((blue1 * Col1Fraction) + (blue2 * (1 - Col1Fraction))); if(endBlue > 255) endBlue = 255; if(endBlue < 0) endBlue = 0; return "#" + IntToHex(endRed)+ IntToHex(endGreen)+ IntToHex(endBlue);} +function IntToHex(strNum) +{ base = strNum / 16; rem = strNum % 16; base = base - (rem / 16); baseS = MakeHex(base); remS = MakeHex(rem); return baseS + '' + remS;} +function MakeHex(x) +{ if((x >= 0) && (x <= 9)) +{ return x;} +else +{ switch(x) +{ case 10: return "A"; case 11: return "B"; case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F";} +} +} +function pixelFraction(x, y, r) +{ var pixelfraction = 0; var xvalues = new Array(1); var yvalues = new Array(1); var point = 0; var whatsides = ""; var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x,2))); if ((intersect >= y) && (intersect < (y+1))) +{ whatsides = "Left"; xvalues[point] = 0; yvalues[point] = intersect - y; point = point + 1;} +var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y+1,2))); if ((intersect >= x) && (intersect < (x+1))) +{ whatsides = whatsides + "Top"; xvalues[point] = intersect - x; yvalues[point] = 1; point = point + 1;} +var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x+1,2))); if ((intersect >= y) && (intersect < (y+1))) +{ whatsides = whatsides + "Right"; xvalues[point] = 1; yvalues[point] = intersect - y; point = point + 1;} +var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y,2))); if ((intersect >= x) && (intersect < (x+1))) +{ whatsides = whatsides + "Bottom"; xvalues[point] = intersect - x; yvalues[point] = 0;} +switch (whatsides) +{ case "LeftRight": +pixelfraction = Math.min(yvalues[0],yvalues[1]) + ((Math.max(yvalues[0],yvalues[1]) - Math.min(yvalues[0],yvalues[1]))/2); break; case "TopRight": +pixelfraction = 1-(((1-xvalues[0])*(1-yvalues[1]))/2); break; case "TopBottom": +pixelfraction = Math.min(xvalues[0],xvalues[1]) + ((Math.max(xvalues[0],xvalues[1]) - Math.min(xvalues[0],xvalues[1]))/2); break; case "LeftBottom": +pixelfraction = (yvalues[0]*xvalues[1])/2; break; default: +pixelfraction = 1;} +return pixelfraction;} +function rgb2Hex(rgbColour) +{ try{ var rgbArray = rgb2Array(rgbColour); var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); var hexColour = "#" + IntToHex(red) + IntToHex(green) + IntToHex(blue);} +catch(e){ alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex");} +return hexColour;} +function rgb2Array(rgbColour) +{ var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")")); var rgbArray = rgbValues.split(", "); return rgbArray;} +function setOpacity(obj, opacity) +{ opacity = (opacity == 100)?99.999:opacity; if(isSafari && obj.tagName != "IFRAME") +{ var rgbArray = rgb2Array(obj.style.backgroundColor); var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); obj.style.backgroundColor = "rgba(" + red + ", " + green + ", " + blue + ", " + opacity/100 + ")";} +else if(typeof(obj.style.opacity) != "undefined") +{ obj.style.opacity = opacity/100;} +else if(typeof(obj.style.MozOpacity) != "undefined") +{ obj.style.MozOpacity = opacity/100;} +else if(typeof(obj.style.filter) != "undefined") +{ obj.style.filter = "alpha(opacity:" + opacity + ")";} +else if(typeof(obj.style.KHTMLOpacity) != "undefined") +{ obj.style.KHTMLOpacity = opacity/100;} +} +function inArray(array, value) +{ for(var i = 0; i < array.length; i++){ if (array[i] === value) return i;} +return false;} +function inArrayKey(array, value) +{ for(key in array){ if(key === value) return true;} +return false;} +function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true;} +else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r;} +else { elm['on' + evType] = fn;} +} +function removeEvent(obj, evType, fn, useCapture){ if (obj.removeEventListener){ obj.removeEventListener(evType, fn, useCapture); return true;} else if (obj.detachEvent){ var r = obj.detachEvent("on"+evType, fn); return r;} else { alert("Handler could not be removed");} +} +function format_colour(colour) +{ var returnColour = "#ffffff"; if(colour != "" && colour != "transparent") +{ if(colour.substr(0, 3) == "rgb") +{ returnColour = rgb2Hex(colour);} +else if(colour.length == 4) +{ returnColour = "#" + colour.substring(1, 2) + colour.substring(1, 2) + colour.substring(2, 3) + colour.substring(2, 3) + colour.substring(3, 4) + colour.substring(3, 4);} +else +{ returnColour = colour;} +} +return returnColour;} +function get_style(obj, property, propertyNS) +{ try +{ if(obj.currentStyle) +{ var returnVal = eval("obj.currentStyle." + property);} +else +{ if(isSafari && obj.style.display == "none") +{ obj.style.display = ""; var wasHidden = true;} +var returnVal = document.defaultView.getComputedStyle(obj, '').getPropertyValue(propertyNS); if(isSafari && wasHidden) +{ obj.style.display = "none";} +} +} +catch(e) +{ } +return returnVal;} +function getElementsByClass(searchClass, node, tag) +{ var classElements = new Array(); if(node == null) +node = document; if(tag == null) +tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)"); for (i = 0, j = 0; i < elsLen; i++) +{ if(pattern.test(els[i].className)) +{ classElements[j] = els[i]; j++;} +} +return classElements;} +function newCurvyError(errorMessage) +{ return new Error("curvyCorners Error:\n" + errorMessage) +} diff --git a/website/stylesheets/screen.css b/website/stylesheets/screen.css new file mode 100644 index 0000000..4d0c0d8 --- /dev/null +++ b/website/stylesheets/screen.css @@ -0,0 +1,139 @@ +body { + background-color: #E1D1F1; + font-family: "Georgia", sans-serif; + font-size: 16px; + line-height: 1.6em; + padding: 1.6em 0 0 0; + color: #333; +} +h1, h2, h3, h4, h5, h6 { + color: #444; +} +h1 { + font-family: sans-serif; + font-weight: normal; + font-size: 4em; + line-height: 0.8em; + letter-spacing: -0.1ex; + margin: 5px; +} +li { + padding: 0; + margin: 0; + list-style-type: square; +} +a { + color: #5E5AFF; + background-color: #DAC; + font-weight: normal; + text-decoration: underline; +} +blockquote { + font-size: 90%; + font-style: italic; + border-left: 1px solid #111; + padding-left: 1em; +} +.caps { + font-size: 80%; +} + +#main { + width: 45em; + padding: 0; + margin: 0 auto; +} +.coda { + text-align: right; + color: #77f; + font-size: smaller; +} + +table { + font-size: 90%; + line-height: 1.4em; + color: #ff8; + background-color: #111; + padding: 2px 10px 2px 10px; + border-style: dashed; +} + +th { + color: #fff; +} + +td { + padding: 2px 10px 2px 10px; +} + +.success { + color: #0CC52B; +} + +.failed { + color: #E90A1B; +} + +.unknown { + color: #995000; +} +pre, code { + font-family: monospace; + font-size: 90%; + line-height: 1.4em; + color: #ff8; + background-color: #111; + padding: 2px 10px 2px 10px; + overflow: auto; +} +.comment { color: #aaa; font-style: italic; } +.keyword { color: #eff; font-weight: bold; } +.punct { color: #eee; font-weight: bold; } +.symbol { color: #0bb; } +.string { color: #6b4; } +.ident { color: #ff8; } +.constant { color: #66f; } +.regex { color: #ec6; } +.number { color: #F99; } +.expr { color: #227; } + +#version { + float: right; + text-align: right; + font-family: sans-serif; + font-weight: normal; + background-color: #B3ABFF; + color: #141331; + padding: 15px 20px 10px 20px; + margin: 0 auto; + margin-top: 15px; + border: 3px solid #141331; +} + +#version .numbers { + display: block; + font-size: 4em; + line-height: 0.8em; + letter-spacing: -0.1ex; + margin-bottom: 15px; +} + +#version p { + text-decoration: none; + color: #141331; + background-color: #B3ABFF; + margin: 0; + padding: 0; +} + +#version a { + text-decoration: none; + color: #141331; + background-color: #B3ABFF; +} + +.clickable { + cursor: pointer; + cursor: hand; +} + diff --git a/website/template.rhtml b/website/template.rhtml new file mode 100644 index 0000000..cad593b --- /dev/null +++ b/website/template.rhtml @@ -0,0 +1,53 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" /> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title> + <%= title %> + </title> + <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script> +<style> + +</style> + <script type="text/javascript"> + window.onload = function() { + settings = { + tl: { radius: 10 }, + tr: { radius: 10 }, + bl: { radius: 10 }, + br: { radius: 10 }, + antiAlias: true, + autoPad: true, + validTags: ["div"] + } + var versionBox = new curvyCorners(settings, document.getElementById("version")); + versionBox.applyCornersToAll(); + } + </script> +</head> +<body> +<div id="main"> + + <h1><%= title %></h1> + <div id="version" class="clickable" onclick='document.location = "<%= download %>"; return false'> + <p>Get Version</p> + <a href="<%= download %>" class="numbers"><%= version %></a> + </div> + <%= body %> + <p class="coda"> + <a href="[email protected]">Matt Aimonetti</a>, <%= modified.pretty %><br> + Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a> + </p> +</div> + +<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> +</script> +<script type="text/javascript"> +_uacct = "UA-179809-11"; +urchinTracker(); +</script> + +</body> +</html>
stanislauslive/StanMarket
a223657bc617b538a735a146c00b8cfb408892f5
Add define('JQUERY_MENU', 'jd_menu'); ( which will be moved into the database ) has 2 values currently: jd_menu or accordion At bottom of code try them both to see which you'd prefer
diff --git a/oscmall_pub/mall_admin/includes/application_top.php b/oscmall_pub/mall_admin/includes/application_top.php index 9651ded..8e44e30 100644 --- a/oscmall_pub/mall_admin/includes/application_top.php +++ b/oscmall_pub/mall_admin/includes/application_top.php @@ -1,365 +1,369 @@ <?php /* Copyright (c) 2002 - 2005 SystemsManager.Net SystemsManager Technologies oscMall System Version 4 http://www.systemsmanager.net Portions Copyright (c) 2002 osCommerce This source file is subject to version 2.0 of the GPL license, that is bundled with this package in the file LICENSE. If you did not receive a copy of the oscMall System license and are unable to obtain it through the world-wide-web, please send a note to [email protected] so we can mail you a copy immediately. */ // Start the clock for the page parse time log define('PAGE_PARSE_START_TIME', microtime()); // Set the level of error reporting error_reporting(E_ALL & ~E_NOTICE); // check support for register_globals // Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized. if (function_exists('ini_get') && (ini_get('register_globals') == false) && (PHP_VERSION < 4.3) ) { exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory. Please use PHP 4.3+ if register_globals cannot be enabled on the server.'); } // Set the local configuration parameters - mainly for developers if (file_exists('includes/local/configure.php')) include('includes/local/configure.php'); // Include application configuration parameters require('includes/configure.php'); // include the database functions require(DIR_WS_FUNCTIONS . 'database.php'); // make a connection to the database... now smn_db_connect() or die('Unable to connect to database server!'); //define tables used with the project /* gus begin ** require(DIR_WS_INCLUDES . 'database_tables.php'); smn_set_database_tables(); ** gus end */ // Define the project version define('PROJECT_VERSION', 'SystemsManager Technologies oscMall Version 4.0'); // some code to solve compatibility issues require(DIR_WS_FUNCTIONS . 'compatibility.php'); // need to get the store prefix before the definitions are set.... require(DIR_WS_CLASSES . 'mall_setup.php'); if (isset($_GET['ID'])){ $store_id = $_GET['ID']; } elseif (isset($_POST['ID'])){ $store_id = $_POST['ID']; }else{ $store_id = 1; } $store = new mall_setup($store_id); $store->set_store_parameters(); //set the stor type to be used $store_type = $store->get_store_type_name(); //set store images and filename variables /* gus begin ** $store->set_store_variables(); ** gus end */ // set php_self in the local scope $PHP_SELF = (isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']); $request_type = (getenv('HTTPS') == 'on') ? 'NONSSL' : 'NONSSL'; // Used in the "Backup Manager" to compress backups define('LOCAL_EXE_GZIP', '/usr/bin/gzip'); define('LOCAL_EXE_GUNZIP', '/usr/bin/gunzip'); define('LOCAL_EXE_ZIP', '/usr/local/bin/zip'); define('LOCAL_EXE_UNZIP', '/usr/local/bin/unzip'); // customization for the design layout define('BOX_WIDTH', 125); // how wide the boxes should be in pixels (default: 125) // Define how do we update currency exchange rates // Possible values are 'oanda' 'xe' or '' define('CURRENCY_SERVER_PRIMARY', 'oanda'); define('CURRENCY_SERVER_BACKUP', 'xe'); // set the mall application parameters /*Changed the query to display the orders placed from substores in the account history by Cimi*/ /*$configuration_query = smn_db_query("select configuration_key as cfgKey, configuration_value as cfgValue from " . TABLE_CONFIGURATION . " where store_id ='" . $store_id ."' or store_id = '0'");*/ $configuration_query = smn_db_query("select configuration_key as cfgKey, configuration_value as cfgValue from " . TABLE_CONFIGURATION . " where store_id ='" . $store_id ."' or store_id = '0' order by store_id desc"); while ($configuration = smn_db_fetch_array($configuration_query)) { define($configuration['cfgKey'], $configuration['cfgValue']); } // define our general functions used application-wide require(DIR_WS_FUNCTIONS . 'general.php'); require(DIR_WS_FUNCTIONS . 'html_output.php'); require(DIR_WS_FUNCTIONS . 'mall_setup.php'); // include the password crypto functions require(DIR_WS_FUNCTIONS . 'password_funcs.php'); // initialize the logger class require(DIR_WS_CLASSES . 'logger.php'); // include shopping cart class require(DIR_WS_CLASSES . 'shopping_cart.php'); // check to see if php implemented session management functions - if not, include php3/php4 compatible session class if (!function_exists('session_start')) { define('PHP_SESSION_NAME', 'osCMallAdmin'); define('PHP_SESSION_PATH', '/'); define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY); include(DIR_WS_CLASSES . 'sessions.php'); } // define how the session functions will be used require(DIR_WS_FUNCTIONS . 'sessions.php'); // set the session name and save path smn_session_name('osCMallAdmin'); smn_session_save_path(SESSION_WRITE_DIRECTORY); // set the session cookie parameters if (function_exists('session_set_cookie_params')) { session_set_cookie_params(0, DIR_WS_ADMIN); } elseif (function_exists('ini_set')) { ini_set('session.cookie_lifetime', '0'); ini_set('session.cookie_path', DIR_WS_ADMIN); } // lets start our session smn_session_start(); if ( (PHP_VERSION >= 4.3) && function_exists('ini_get') && (ini_get('register_globals') == false) ) { extract($_SESSION, EXTR_OVERWRITE+EXTR_REFS); } if (($_GET['ID']) && (!$store_id) ){ if (!smn_session_is_registered ('store_id')) smn_session_register('store_id'); $store_id = intval($_GET['ID']); } if (!smn_session_is_registered ('store_name')) smn_session_register('store_name'); $store_name = $store->get_store_name(); if (!smn_session_is_registered ('store_group_type')) smn_session_register('store_group_type'); $store_group_type = smn_set_store_group_type($store->get_store_type()); if (!smn_session_is_registered ('store_type')) smn_session_register('store_type'); $store_type = $store->get_store_type(); // set the language if (!smn_session_is_registered('language') || isset($_GET['language'])) { if (!smn_session_is_registered('language')) { smn_session_register('language'); smn_session_register('languages_id'); } include(DIR_WS_CLASSES . 'language.php'); $lng = new language(); if (isset($_GET['language']) && smn_not_null($_GET['language'])) { $lng->set_language($_GET['language']); } else { $lng->get_browser_language(); } $language = $lng->language['directory']; $languages_id = $lng->language['id']; } // include the language translations require(DIR_WS_LANGUAGES . $language . '.php'); $current_page = basename($PHP_SELF); if (file_exists(DIR_WS_LANGUAGES . $language . '/' . $current_page)) { include(DIR_WS_LANGUAGES . $language . '/' . $current_page); } // define our localization functions require(DIR_WS_FUNCTIONS . 'localization.php'); // Include validation functions (right now only email address) require(DIR_WS_FUNCTIONS . 'validations.php'); // setup our boxes require(DIR_WS_CLASSES . 'table_block.php'); require(DIR_WS_CLASSES . 'box.php'); // initialize the message stack for output messages require(DIR_WS_CLASSES . 'message_stack.php'); $messageStack = new messageStack; // split-page-results require(DIR_WS_CLASSES . 'split_page_results.php'); // entry/item info classes require(DIR_WS_CLASSES . 'object_info.php'); // email classes require(DIR_WS_CLASSES . 'mime.php'); require(DIR_WS_CLASSES . 'email.php'); // file uploading class require(DIR_WS_CLASSES . 'upload.php'); // calculate category path if (isset($_GET['cPath'])) { $cPath = $_GET['cPath']; } elseif (isset($_POST['cPath'])) { $cPath = $_POST['cPath']; }else{ $cPath = ''; } if (smn_not_null($cPath)) { $cPath_array = smn_parse_category_path($cPath); $cPath = implode('_', $cPath_array); $current_category_id = $cPath_array[(sizeof($cPath_array)-1)]; } else { $current_category_id = 0; } // calculate category path if (isset($_GET['sPath'])) { $sPath = $_GET['sPath']; } elseif (isset($_POST['sPath'])) { $sPath = $_POST['sPath']; }else{ $sPath = ''; } if (smn_not_null($sPath)) { $sPath_array = smn_parse_store_category_path($sPath); $sPath = implode('_', $sPath_array); $current_store_category_id = $sPath_array[(sizeof($sPath_array)-1)]; } else { $current_store_category_id = 0; } // default open navigation box if (!smn_session_is_registered('selected_box')) { smn_session_register('selected_box'); $selected_box = 'configuration'; } if (isset($_GET['selected_box'])) { $selected_box = $_GET['selected_box']; } // the following cache blocks are used in the Tools->Cache section // ('language' in the filename is automatically replaced by available languages) $cache_blocks = array(array('title' => TEXT_CACHE_CATEGORIES, 'code' => 'categories', 'file' => 'categories_box-language.cache', 'multiple' => true), array('title' => TEXT_CACHE_MANUFACTURERS, 'code' => 'manufacturers', 'file' => 'manufacturers_box-language.cache', 'multiple' => true), array('title' => TEXT_CACHE_ALSO_PURCHASED, 'code' => 'also_purchased', 'file' => 'also_purchased-language.cache', 'multiple' => true) ); // check if a default currency is set if (!defined('DEFAULT_CURRENCY')) { $messageStack->add(ERROR_NO_DEFAULT_CURRENCY_DEFINED, 'error'); } // check if a default language is set if (!defined('DEFAULT_LANGUAGE')) { $messageStack->add(ERROR_NO_DEFAULT_LANGUAGE_DEFINED, 'error'); } if (function_exists('ini_get') && ((bool)ini_get('file_uploads') == false) ) { $messageStack->add(WARNING_FILE_UPLOADS_DISABLED, 'warning'); } // set the store_id if (smn_session_is_registered('login_id')) { $store_id_check = smn_db_query("select admin_id, admin_groups_id, store_id from " . TABLE_ADMIN . " where admin_id = '". $login_id."'"); $check = smn_db_fetch_array($store_id_check); $switch_store_id = $check['store_id']; if (!smn_session_is_registered ('switch_store_id'))smn_session_register('switch_store_id'); if (($check['admin_id'] == 1 )&& ($check['store_id'] == 1 )&& ($check['admin_groups_id'] == 1 )) { $super_user = 'true'; if (!smn_session_is_registered ('super_user')) smn_session_register('super_user'); if (isset ($_POST['store'])){ smn_session_unregister('store_id'); $store_id = $_POST['store']; smn_session_register('store_id'); smn_redirect(smn_href_link(basename($PHP_SELF))); } }else{ $super_user = 'false'; if (!smn_session_is_registered ('super_user')) smn_session_register('super_user'); if (intval($_GET['ID']) != intval($switch_store_id)) smn_redirect(smn_href_link(FILENAME_LOGOFF)); $store_id = $check['store_id']; smn_session_register('store_id'); } $filename = basename( $PHP_SELF ); if ($filename != FILENAME_DEFAULT && $filename != FILENAME_FORBIDEN && $filename != FILENAME_LOGOFF && $filename != FILENAME_ADMIN_ACCOUNT && $filename != FILENAME_POPUP_IMAGE && $filename != 'packingslip.php' && $filename != 'invoice.php') { $db_file_query = smn_db_query("select admin_files_name, admin_groups_id from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_name = '" . $filename . "'"); if (!smn_db_num_rows($db_file_query)) { //smn_redirect(smn_href_link(FILENAME_FORBIDEN)); }else{ $db_file = smn_db_fetch_array($db_file_query); } } } // Check login and file access if (basename($PHP_SELF) != FILENAME_LOGOFF && basename($PHP_SELF) != FILENAME_LOGIN && basename($PHP_SELF) != FILENAME_PASSWORD_FORGOTTEN) { if (!smn_session_is_registered('login_id')) { smn_session_unregister('store_id'); smn_session_unregister('login_id'); if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ echo '{ success: false, errorType: "login", errorMsg: "Your Login Session Has Expired, Use The Fields Below To Login." }'; exit; } smn_redirect(smn_href_link(FILENAME_LOGIN, '', 'NONSSL')); } } define ('AFFILIATE_NOTIFY_AFTER_BILLING','true'); // Nofify affiliate if he got a new invoice define ('AFFILIATE_DELETE_ORDERS','false'); // Delete affiliate_sales if an order is deleted (Warning: Only not yet billed sales are deleted) define ('AFFILIATE_TAX_ID','1'); // Tax Rates used for billing the affiliates // you get this from the URl (tID) when you select you Tax Rate at the admin: tax_rates.php?tID=1 // If set, the following actions take place each time you call the admin/affiliate_summary define ('AFFILIATE_DELETE_CLICKTHROUGHS','false'); // (days / false) To keep the clickthrough report small you can set the days after which they are deleted (when calling affiliate_summary in the admin) define ('AFFILIATE_DELETE_AFFILIATE_BANNER_HISTORY','false'); // (days / false) To keep thethe table AFFILIATE_BANNER_HISTORY small you can set the days after which they are deleted (when calling affiliate_summary in the admin) // If an order is deleted delete the sale too (optional) if ($_GET['action'] == 'deleteconfirm' && basename($HTTP_SERVER_VARS['SCRIPT_FILENAME']) == FILENAME_ORDERS && AFFILIATE_DELETE_ORDERS == 'true') { $affiliate_oID = smn_db_prepare_input($_GET['oID']); smn_db_query("delete from " . TABLE_AFFILIATE_SALES . " where affiliate_orders_id = '" . smn_db_input($affiliate_oID) . "' and affiliate_billing_status != 1"); } define('SECURITY_CODE_LENGTH', '6'); require('../includes/classes/jQuery.php'); $jQuery = new jQuery(); $jQuery->loadAllExtensions(); - $jQuery->loadAllPlugins(); + $jQuery->loadAllPlugins(); + +// +// This define('JQUERY_MENU', 'jd_menu'); ( which will be moved into the database ) has 2 values currently: jd_menu or ??// accordion +define('JQUERY_MENU', 'jd_menu'); ?> \ No newline at end of file
nullset/digitalvision-patch
fdabadf6e73f314921bb386249a25f2757d8c901
Compare script, and db results
diff --git a/digitalvision.rb b/digitalvision.rb index 13b1e18..c16b040 100644 --- a/digitalvision.rb +++ b/digitalvision.rb @@ -1,140 +1,196 @@ require 'rubygems' require 'find' require 'digest/md5' # require 'open-uri' require 'typhoeus' +require 'carrot' require 'cgi' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => '/Users/nn/projects/wrayco/digitalvision-patch/digitalvision.sqlite3', :pool => 5, :timeout => 5000 ) class Item < ActiveRecord::Base end ActiveRecord::Base.logger = Logger.new(STDOUT) class HackCheck def initialize(root_local_path, website) @root_local_path = root_local_path @website = website @base_path = '' @filename = '' @item = nil + @add_count = 0 + @pop_count = 0 @ignore_files = ['.wmv', '.avi', '.mov', '.mp4', '.flv', '.mpg', '.jpg', '.tif', '.zip'].collect {|f| [f, f.upcase] }.flatten + @q = Carrot.queue('input_files') + # monitor_queue + end + + def monitor_queue + puts '---> Now monitoring queue' + while path = @q.pop(:ack => true) + puts "Popping: #{path}" + pull(path) + @q.ack + @pop_count += 1 + end + Carrot.stop end def check - i = 0 start_time = Time.now - Find.find(@root_local_path) do |path| - if File.file?(path) - next if @ignore_files.include?(File.extname(path)) - @base_path = path.sub(@root_local_path, '') - @filename = File.basename(@base_path) - local_hash = Digest::MD5.hexdigest(File.read(path)) - @item = Item.find_by_path(@base_path) - url = @website + @base_path - - # begin - request = Remote.get(url.gsub(/ /, '%20')) # open(CGI::escape(url)) - if request.code == 200 - remote_hash = Digest::MD5.hexdigest(request.body) - if remote_hash == local_hash - state = 'synced' - else - state = 'different' - end - - if @item - @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :code => nil, :message => nil, :updated_at => Time.now) - else - @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) - end - else - code = request.code - message = request.headers - if @item - remote_hash ||= nil - @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :code => code, :message => message, :updated_at => Time.now) - else - @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :code => code, :message => message) - end - end - - # rescue => e - # file = nil - # message = e.message - # end - - # if file - # # can open file remotely - # remote_hash = Digest::MD5.hexdigest(file.body) - # if remote_hash == local_hash - # state = 'synced' - # else - # state = 'different' - # end - # - # if @item - # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :message => nil, :updated_at => Time.now) - # else - # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) - # end - # else - # # can't open file - # if @item - # remote_hash ||= nil - # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :message => message, :updated_at => Time.now) - # else - # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :message => message) - # end - # end - i += 1 - end + + Find.find(@root_local_path) do |path| + # next if File.directory?(path) + next if @ignore_files.include?(File.extname(path)) + puts "Adding: #{path}" + @q.publish(path) + @add_count += 1 end + + monitor_queue + end_time = Time.now - puts "Took #{end_time - start_time} seconds to process #{i} files" + puts "\nIt took #{end_time - start_time} seconds to process #{@add_count} queued files (#{@pop_count} popped)" + + # Find.find(@root_local_path) do |path| + # if File.file?(path) + # next if @ignore_files.include?(File.extname(path)) + # @base_path = path.sub(@root_local_path, '') + # @filename = File.basename(@base_path) + # local_hash = Digest::MD5.hexdigest(File.read(path)) + # @item = Item.find_by_path(@base_path) + # url = @website + @base_path + # + # # begin + # request = Remote.get(url.gsub(/ /, '%20')) # open(CGI::escape(url)) + # if request.code == 200 + # remote_hash = Digest::MD5.hexdigest(request.body) + # if remote_hash == local_hash + # state = 'synced' + # else + # state = 'different' + # end + # + # if @item + # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :code => nil, :message => nil, :updated_at => Time.now) + # else + # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) + # end + # else + # code = request.code + # message = request.headers + # if @item + # remote_hash ||= nil + # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :code => code, :message => message, :updated_at => Time.now) + # else + # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :code => code, :message => message) + # end + # end + # + # # rescue => e + # # file = nil + # # message = e.message + # # end + # + # # if file + # # # can open file remotely + # # remote_hash = Digest::MD5.hexdigest(file.body) + # # if remote_hash == local_hash + # # state = 'synced' + # # else + # # state = 'different' + # # end + # # + # # if @item + # # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :message => nil, :updated_at => Time.now) + # # else + # # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) + # # end + # # else + # # # can't open file + # # if @item + # # remote_hash ||= nil + # # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :message => message, :updated_at => Time.now) + # # else + # # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :message => message) + # # end + # # end + # i += 1 + # end + # end end - def file_in_db - puts @item.inspect - return false if @item.nil? - return true + def pull(path) + if File.file?(path) + @base_path = path.sub(@root_local_path, '') + @filename = File.basename(@base_path) + local_hash = Digest::MD5.hexdigest(File.read(path)) + @item = Item.find_by_path(@base_path) + url = @website + @base_path + + request = Remote.get(url.gsub(/ /, '%20')) # open(CGI::escape(url)) + if request.code == 200 + remote_hash = Digest::MD5.hexdigest(request.body) + if remote_hash == local_hash + state = 'synced' + else + state = 'different' + end + + if @item + @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :code => nil, :message => nil, :updated_at => Time.now) + else + @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) + end + else + code = request.code + message = request.headers + if @item + remote_hash ||= nil + @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :code => code, :message => message, :updated_at => Time.now) + else + @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :code => code, :message => message) + end + end + end end end class Remote include Typhoeus end class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| t.string :filename, :null => false t.string :state, :default => 'unsynced' t.integer :code t.string :message t.string :path, :null => false t.string :local_hash t.string :url, :null => false t.string :remote_hash t.string :message t.datetime :created_at t.datetime :updated_at end add_index :items, :path add_index :items, :state end def self.down drop_table :items end end # CreateItems.up h = HackCheck.new('/Users/nn/Downloads/digitalvision', 'http://www.digitalvision.se') h.check \ No newline at end of file diff --git a/digitalvision.sqlite3 b/digitalvision.sqlite3 index 0bcddde..c01a191 100644 Binary files a/digitalvision.sqlite3 and b/digitalvision.sqlite3 differ
nullset/digitalvision-patch
afff3bcf9e71dae1c3cd14154c5d58e67135e88c
Typhoeus working.
diff --git a/digitalvision.rb b/digitalvision.rb index 19a0f50..13b1e18 100644 --- a/digitalvision.rb +++ b/digitalvision.rb @@ -1,131 +1,140 @@ require 'rubygems' require 'find' require 'digest/md5' -require 'open-uri' +# require 'open-uri' +require 'typhoeus' require 'cgi' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', - :database => '/Users/nn/Desktop/digitalvision.sqlite3', + :database => '/Users/nn/projects/wrayco/digitalvision-patch/digitalvision.sqlite3', :pool => 5, :timeout => 5000 ) class Item < ActiveRecord::Base end ActiveRecord::Base.logger = Logger.new(STDOUT) -# -# i = 0 -# root = '/Users/nn/Downloads/digitalvision' -# Find.find(root) do |path| -# # if File.basename(path) =~ /file2$/ -# # puts "PRUNED #{path}" -# # Find.prune -# # end -# if File.file?(path) -# local_hash = Digest::MD5.hexdigest(File.read(path)) -# Item.create(:path => path.sub(root, ''), :local_hash => local_hash) -# i += 1 -# break if i == 10 -# end -# end -# -# puts "There are #{i} things" -# # 13579 files - - class HackCheck def initialize(root_local_path, website) @root_local_path = root_local_path @website = website @base_path = '' @filename = '' @item = nil - @ignore_files = ['.wmv', '.avi', '.mov', '.mp4', '.flv', '.mpg', '.jpg', '.tif', '.zip'] - @ignore_files = @ignore_files.collect {|i| [i, i.upcase] }.flatten + @ignore_files = ['.wmv', '.avi', '.mov', '.mp4', '.flv', '.mpg', '.jpg', '.tif', '.zip'].collect {|f| [f, f.upcase] }.flatten end def check i = 0 start_time = Time.now Find.find(@root_local_path) do |path| if File.file?(path) next if @ignore_files.include?(File.extname(path)) @base_path = path.sub(@root_local_path, '') @filename = File.basename(@base_path) local_hash = Digest::MD5.hexdigest(File.read(path)) @item = Item.find_by_path(@base_path) url = @website + @base_path - begin - file = open(url.gsub(/ /, '%20')) # open(CGI::escape(url)) - rescue => e - file = nil - message = e.message - end - - if file - # can open file remotely - remote_hash = Digest::MD5.hexdigest(file.read) - if remote_hash == local_hash - state = 'synced' - else - state = 'different' - end - - if @item - @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :message => nil, :updated_at => Time.now) - else - @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) - end - else - # can't open file - if @item - remote_hash ||= nil - @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :message => message, :updated_at => Time.now) + # begin + request = Remote.get(url.gsub(/ /, '%20')) # open(CGI::escape(url)) + if request.code == 200 + remote_hash = Digest::MD5.hexdigest(request.body) + if remote_hash == local_hash + state = 'synced' + else + state = 'different' + end + + if @item + @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :code => nil, :message => nil, :updated_at => Time.now) + else + @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) + end else - @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :message => message) + code = request.code + message = request.headers + if @item + remote_hash ||= nil + @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :code => code, :message => message, :updated_at => Time.now) + else + @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :code => code, :message => message) + end end - end + + # rescue => e + # file = nil + # message = e.message + # end + + # if file + # # can open file remotely + # remote_hash = Digest::MD5.hexdigest(file.body) + # if remote_hash == local_hash + # state = 'synced' + # else + # state = 'different' + # end + # + # if @item + # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => state, :message => nil, :updated_at => Time.now) + # else + # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :remote_hash => remote_hash, :state => state) + # end + # else + # # can't open file + # if @item + # remote_hash ||= nil + # @item.update_attributes(:local_hash => local_hash, :remote_hash => remote_hash, :state => 'unsynced', :message => message, :updated_at => Time.now) + # else + # @item = Item.create(:filename => @filename, :path => @base_path, :local_hash => local_hash, :url => url, :message => message) + # end + # end i += 1 end end end_time = Time.now puts "Took #{end_time - start_time} seconds to process #{i} files" end def file_in_db puts @item.inspect return false if @item.nil? return true end end +class Remote + include Typhoeus +end + class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| t.string :filename, :null => false t.string :state, :default => 'unsynced' + t.integer :code t.string :message t.string :path, :null => false t.string :local_hash t.string :url, :null => false t.string :remote_hash t.string :message t.datetime :created_at t.datetime :updated_at end add_index :items, :path add_index :items, :state end def self.down drop_table :items end end # CreateItems.up h = HackCheck.new('/Users/nn/Downloads/digitalvision', 'http://www.digitalvision.se') h.check \ No newline at end of file diff --git a/digitalvision.sqlite3 b/digitalvision.sqlite3 index 56c511b..0bcddde 100644 Binary files a/digitalvision.sqlite3 and b/digitalvision.sqlite3 differ
dny/as-lin-eye
a9f8a194fe32c2dad15138345c4675b7c81290a1
ist jetzt unter BSD lizenz!
diff --git a/eye-linkinus.txt b/eye-linkinus.txt index e0624f1..36b30eb 100644 --- a/eye-linkinus.txt +++ b/eye-linkinus.txt @@ -1,11 +1,12 @@ (* -Lizenzding +Lizenzding +This script is under BSD-License *) on linkinuscmd() tell application "EyeTV" activate channel_change channel number 6 volume_change level 0.5 end tell return / dev / null end linkinuscmd
dny/as-lin-eye
4fcb882d3957dd0e3264676e77a15fc845096b89
das is jetz auf github
diff --git a/eye-linkinus.txt b/eye-linkinus.txt new file mode 100644 index 0000000..e0624f1 --- /dev/null +++ b/eye-linkinus.txt @@ -0,0 +1,11 @@ +(* +Lizenzding +*) +on linkinuscmd() + tell application "EyeTV" + activate + channel_change channel number 6 + volume_change level 0.5 + end tell + return / dev / null +end linkinuscmd
dny/as-lin-eye
69b930aa0ca27e27630969d1e187956ff300d88a
first comit
diff --git a/README b/README new file mode 100644 index 0000000..e69de29
BastyCDGS/ffmpeg-soc
d2a4571e14a7ac952eb016b1f051f91462efb3f2
modifié : libavsequencer/player.c
diff --git a/libavcodec/x86/h264_qpel_mmx.c b/libavcodec/x86/h264_qpel_mmx.c index d8ceca1..f5af44e 100644 --- a/libavcodec/x86/h264_qpel_mmx.c +++ b/libavcodec/x86/h264_qpel_mmx.c @@ -1,1201 +1,1201 @@ /* * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "dsputil_mmx.h" /***********************************/ /* motion compensation */ #define QPEL_H264V_MM(A,B,C,D,E,F,OP,T,Z,d,q)\ "mov"#q" "#C", "#T" \n\t"\ "mov"#d" (%0), "#F" \n\t"\ "paddw "#D", "#T" \n\t"\ "psllw $2, "#T" \n\t"\ "psubw "#B", "#T" \n\t"\ "psubw "#E", "#T" \n\t"\ "punpcklbw "#Z", "#F" \n\t"\ "pmullw "MANGLE(ff_pw_5)", "#T"\n\t"\ "paddw "MANGLE(ff_pw_16)", "#A"\n\t"\ "add %2, %0 \n\t"\ "paddw "#F", "#A" \n\t"\ "paddw "#A", "#T" \n\t"\ "psraw $5, "#T" \n\t"\ "packuswb "#T", "#T" \n\t"\ OP(T, (%1), A, d)\ "add %3, %1 \n\t" #define QPEL_H264HV_MM(A,B,C,D,E,F,OF,T,Z,d,q)\ "mov"#q" "#C", "#T" \n\t"\ "mov"#d" (%0), "#F" \n\t"\ "paddw "#D", "#T" \n\t"\ "psllw $2, "#T" \n\t"\ "paddw "MANGLE(ff_pw_16)", "#A"\n\t"\ "psubw "#B", "#T" \n\t"\ "psubw "#E", "#T" \n\t"\ "punpcklbw "#Z", "#F" \n\t"\ "pmullw "MANGLE(ff_pw_5)", "#T"\n\t"\ "paddw "#F", "#A" \n\t"\ "add %2, %0 \n\t"\ "paddw "#A", "#T" \n\t"\ "mov"#q" "#T", "#OF"(%1) \n\t" #define QPEL_H264V(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%mm6,%%mm7,d,q) #define QPEL_H264HV(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%mm6,%%mm7,d,q) #define QPEL_H264V_XMM(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%xmm6,%%xmm7,q,dqa) #define QPEL_H264HV_XMM(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%xmm6,%%xmm7,q,dqa) #define QPEL_H264(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ int h=4;\ \ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movq "MANGLE(ff_pw_5) ", %%mm4\n\t"\ "movq "MANGLE(ff_pw_16)", %%mm5\n\t"\ "1: \n\t"\ "movd -1(%0), %%mm1 \n\t"\ "movd (%0), %%mm2 \n\t"\ "movd 1(%0), %%mm3 \n\t"\ "movd 2(%0), %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "paddw %%mm0, %%mm1 \n\t"\ "paddw %%mm3, %%mm2 \n\t"\ "movd -2(%0), %%mm0 \n\t"\ "movd 3(%0), %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "paddw %%mm3, %%mm0 \n\t"\ "psllw $2, %%mm2 \n\t"\ "psubw %%mm1, %%mm2 \n\t"\ "pmullw %%mm4, %%mm2 \n\t"\ "paddw %%mm5, %%mm0 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "psraw $5, %%mm0 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm6, d)\ "add %3, %0 \n\t"\ "add %4, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ int h=4;\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movq %0, %%mm4 \n\t"\ "movq %1, %%mm5 \n\t"\ :: "m"(ff_pw_5), "m"(ff_pw_16)\ );\ do{\ __asm__ volatile(\ "movd -1(%0), %%mm1 \n\t"\ "movd (%0), %%mm2 \n\t"\ "movd 1(%0), %%mm3 \n\t"\ "movd 2(%0), %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "paddw %%mm0, %%mm1 \n\t"\ "paddw %%mm3, %%mm2 \n\t"\ "movd -2(%0), %%mm0 \n\t"\ "movd 3(%0), %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "paddw %%mm3, %%mm0 \n\t"\ "psllw $2, %%mm2 \n\t"\ "psubw %%mm1, %%mm2 \n\t"\ "pmullw %%mm4, %%mm2 \n\t"\ "paddw %%mm5, %%mm0 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "movd (%2), %%mm3 \n\t"\ "psraw $5, %%mm0 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ PAVGB" %%mm3, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm6, d)\ "add %4, %0 \n\t"\ "add %4, %1 \n\t"\ "add %3, %2 \n\t"\ : "+a"(src), "+c"(dst), "+d"(src2)\ : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }while(--h);\ }\ static av_noinline void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ src -= 2*srcStride;\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movd (%0), %%mm0 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm1 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm2 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm3 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm4 \n\t"\ "add %2, %0 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ \ : "+a"(src), "+c"(dst)\ : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ }\ static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ int h=4;\ int w=3;\ src -= 2*srcStride+2;\ while(w--){\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movd (%0), %%mm0 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm1 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm2 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm3 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm4 \n\t"\ "add %2, %0 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\ \ : "+a"(src)\ : "c"(tmp), "S"((x86_reg)srcStride)\ : "memory"\ );\ tmp += 4;\ src += 4 - 9*srcStride;\ }\ tmp -= 3*4;\ __asm__ volatile(\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "paddw 10(%0), %%mm0 \n\t"\ "movq 2(%0), %%mm1 \n\t"\ "paddw 8(%0), %%mm1 \n\t"\ "movq 4(%0), %%mm2 \n\t"\ "paddw 6(%0), %%mm2 \n\t"\ "psubw %%mm1, %%mm0 \n\t"/*a-b (abccba)*/\ "psraw $2, %%mm0 \n\t"/*(a-b)/4 */\ "psubw %%mm1, %%mm0 \n\t"/*(a-b)/4-b */\ "paddsw %%mm2, %%mm0 \n\t"\ "psraw $2, %%mm0 \n\t"/*((a-b)/4-b+c)/4 */\ "paddw %%mm2, %%mm0 \n\t"/*(a-5*b+20*c)/16 */\ "psraw $6, %%mm0 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm7, d)\ "add $24, %0 \n\t"\ "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(tmp), "+c"(dst), "+g"(h)\ : "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ \ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ int h=8;\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movq "MANGLE(ff_pw_5)", %%mm6\n\t"\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "movq 1(%0), %%mm2 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm2, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpckhbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpckhbw %%mm7, %%mm3 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm3, %%mm1 \n\t"\ "psllw $2, %%mm0 \n\t"\ "psllw $2, %%mm1 \n\t"\ "movq -1(%0), %%mm2 \n\t"\ "movq 2(%0), %%mm4 \n\t"\ "movq %%mm2, %%mm3 \n\t"\ "movq %%mm4, %%mm5 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpckhbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ "punpckhbw %%mm7, %%mm5 \n\t"\ "paddw %%mm4, %%mm2 \n\t"\ "paddw %%mm3, %%mm5 \n\t"\ "psubw %%mm2, %%mm0 \n\t"\ "psubw %%mm5, %%mm1 \n\t"\ "pmullw %%mm6, %%mm0 \n\t"\ "pmullw %%mm6, %%mm1 \n\t"\ "movd -2(%0), %%mm2 \n\t"\ "movd 7(%0), %%mm5 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm5 \n\t"\ "paddw %%mm3, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ "movq "MANGLE(ff_pw_16)", %%mm5\n\t"\ "paddw %%mm5, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm4, %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "packuswb %%mm1, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm5, q)\ "add %3, %0 \n\t"\ "add %4, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ \ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ int h=8;\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movq "MANGLE(ff_pw_5)", %%mm6\n\t"\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "movq 1(%0), %%mm2 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm2, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpckhbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpckhbw %%mm7, %%mm3 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm3, %%mm1 \n\t"\ "psllw $2, %%mm0 \n\t"\ "psllw $2, %%mm1 \n\t"\ "movq -1(%0), %%mm2 \n\t"\ "movq 2(%0), %%mm4 \n\t"\ "movq %%mm2, %%mm3 \n\t"\ "movq %%mm4, %%mm5 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpckhbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ "punpckhbw %%mm7, %%mm5 \n\t"\ "paddw %%mm4, %%mm2 \n\t"\ "paddw %%mm3, %%mm5 \n\t"\ "psubw %%mm2, %%mm0 \n\t"\ "psubw %%mm5, %%mm1 \n\t"\ "pmullw %%mm6, %%mm0 \n\t"\ "pmullw %%mm6, %%mm1 \n\t"\ "movd -2(%0), %%mm2 \n\t"\ "movd 7(%0), %%mm5 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm5 \n\t"\ "paddw %%mm3, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ "movq "MANGLE(ff_pw_16)", %%mm5\n\t"\ "paddw %%mm5, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm4, %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "movq (%2), %%mm4 \n\t"\ "packuswb %%mm1, %%mm0 \n\t"\ PAVGB" %%mm4, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm5, q)\ "add %5, %0 \n\t"\ "add %5, %1 \n\t"\ "add %4, %2 \n\t"\ "decl %3 \n\t"\ "jg 1b \n\t"\ : "+a"(src), "+c"(dst), "+d"(src2), "+g"(h)\ : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ \ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ int w= 2;\ src -= 2*srcStride;\ \ while(w--){\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movd (%0), %%mm0 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm1 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm2 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm3 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm4 \n\t"\ "add %2, %0 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ "cmpl $16, %4 \n\t"\ "jne 2f \n\t"\ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ "2: \n\t"\ \ : "+a"(src), "+c"(dst)\ - : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\ + : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\ : "memory"\ );\ src += 4-(h+5)*srcStride;\ dst += 4-h*dstStride;\ }\ }\ static av_always_inline void OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){\ int w = (size+8)>>2;\ src -= 2*srcStride+2;\ while(w--){\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ "movd (%0), %%mm0 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm1 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm2 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm3 \n\t"\ "add %2, %0 \n\t"\ "movd (%0), %%mm4 \n\t"\ "add %2, %0 \n\t"\ "punpcklbw %%mm7, %%mm0 \n\t"\ "punpcklbw %%mm7, %%mm1 \n\t"\ "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\ QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\ QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\ "cmpl $16, %3 \n\t"\ "jne 2f \n\t"\ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 8*48)\ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 9*48)\ QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\ QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\ "2: \n\t"\ : "+a"(src)\ - : "c"(tmp), "S"((x86_reg)srcStride), "g"(size)\ + : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size)\ : "memory"\ );\ tmp += 4;\ src += 4 - (size+5)*srcStride;\ }\ }\ static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\ int w = size>>4;\ do{\ int h = size;\ __asm__ volatile(\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "movq 8(%0), %%mm3 \n\t"\ "movq 2(%0), %%mm1 \n\t"\ "movq 10(%0), %%mm4 \n\t"\ "paddw %%mm4, %%mm0 \n\t"\ "paddw %%mm3, %%mm1 \n\t"\ "paddw 18(%0), %%mm3 \n\t"\ "paddw 16(%0), %%mm4 \n\t"\ "movq 4(%0), %%mm2 \n\t"\ "movq 12(%0), %%mm5 \n\t"\ "paddw 6(%0), %%mm2 \n\t"\ "paddw 14(%0), %%mm5 \n\t"\ "psubw %%mm1, %%mm0 \n\t"\ "psubw %%mm4, %%mm3 \n\t"\ "psraw $2, %%mm0 \n\t"\ "psraw $2, %%mm3 \n\t"\ "psubw %%mm1, %%mm0 \n\t"\ "psubw %%mm4, %%mm3 \n\t"\ "paddsw %%mm2, %%mm0 \n\t"\ "paddsw %%mm5, %%mm3 \n\t"\ "psraw $2, %%mm0 \n\t"\ "psraw $2, %%mm3 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm5, %%mm3 \n\t"\ "psraw $6, %%mm0 \n\t"\ "psraw $6, %%mm3 \n\t"\ "packuswb %%mm3, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm7, q)\ "add $48, %0 \n\t"\ "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(tmp), "+c"(dst), "+g"(h)\ : "S"((x86_reg)dstStride)\ : "memory"\ );\ tmp += 8 - size*24;\ dst += 8 - size*dstStride;\ }while(w--);\ }\ \ static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\ }\ static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ }\ \ static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ src += 8*srcStride;\ dst += 8*dstStride;\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ }\ \ static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ src += 8*dstStride;\ dst += 8*dstStride;\ src2 += 8*src2Stride;\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ }\ \ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\ put_h264_qpel8or16_hv1_lowpass_ ## MMX(tmp, src, tmpStride, srcStride, size);\ OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\ }\ static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\ }\ \ static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 16);\ }\ \ static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ __asm__ volatile(\ "movq (%1), %%mm0 \n\t"\ "movq 24(%1), %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ "packuswb %%mm1, %%mm1 \n\t"\ PAVGB" (%0), %%mm0 \n\t"\ PAVGB" (%0,%3), %%mm1 \n\t"\ OP(%%mm0, (%2), %%mm4, d)\ OP(%%mm1, (%2,%4), %%mm5, d)\ "lea (%0,%3,2), %0 \n\t"\ "lea (%2,%4,2), %2 \n\t"\ "movq 48(%1), %%mm0 \n\t"\ "movq 72(%1), %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ "packuswb %%mm1, %%mm1 \n\t"\ PAVGB" (%0), %%mm0 \n\t"\ PAVGB" (%0,%3), %%mm1 \n\t"\ OP(%%mm0, (%2), %%mm4, d)\ OP(%%mm1, (%2,%4), %%mm5, d)\ :"+a"(src8), "+c"(src16), "+d"(dst)\ :"S"((x86_reg)src8Stride), "D"((x86_reg)dstStride)\ :"memory");\ }\ static av_noinline void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ do{\ __asm__ volatile(\ "movq (%1), %%mm0 \n\t"\ "movq 8(%1), %%mm1 \n\t"\ "movq 48(%1), %%mm2 \n\t"\ "movq 8+48(%1), %%mm3 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "psraw $5, %%mm2 \n\t"\ "psraw $5, %%mm3 \n\t"\ "packuswb %%mm1, %%mm0 \n\t"\ "packuswb %%mm3, %%mm2 \n\t"\ PAVGB" (%0), %%mm0 \n\t"\ PAVGB" (%0,%3), %%mm2 \n\t"\ OP(%%mm0, (%2), %%mm5, q)\ OP(%%mm2, (%2,%4), %%mm5, q)\ ::"a"(src8), "c"(src16), "d"(dst),\ "r"((x86_reg)src8Stride), "r"((x86_reg)dstStride)\ :"memory");\ src8 += 2L*src8Stride;\ src16 += 48;\ dst += 2L*dstStride;\ }while(h-=2);\ }\ static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ OPNAME ## pixels8_l2_shift5_ ## MMX(dst , src16 , src8 , dstStride, src8Stride, h);\ OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\ }\ #if ARCH_X86_64 #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ int h=16;\ __asm__ volatile(\ "pxor %%xmm15, %%xmm15 \n\t"\ "movdqa %6, %%xmm14 \n\t"\ "movdqa %7, %%xmm13 \n\t"\ "1: \n\t"\ "lddqu 6(%0), %%xmm1 \n\t"\ "lddqu -2(%0), %%xmm7 \n\t"\ "movdqa %%xmm1, %%xmm0 \n\t"\ "punpckhbw %%xmm15, %%xmm1 \n\t"\ "punpcklbw %%xmm15, %%xmm0 \n\t"\ "punpcklbw %%xmm15, %%xmm7 \n\t"\ "movdqa %%xmm1, %%xmm2 \n\t"\ "movdqa %%xmm0, %%xmm6 \n\t"\ "movdqa %%xmm1, %%xmm3 \n\t"\ "movdqa %%xmm0, %%xmm8 \n\t"\ "movdqa %%xmm1, %%xmm4 \n\t"\ "movdqa %%xmm0, %%xmm9 \n\t"\ "movdqa %%xmm0, %%xmm12 \n\t"\ "movdqa %%xmm1, %%xmm11 \n\t"\ "palignr $10,%%xmm0, %%xmm11\n\t"\ "palignr $10,%%xmm7, %%xmm12\n\t"\ "palignr $2, %%xmm0, %%xmm4 \n\t"\ "palignr $2, %%xmm7, %%xmm9 \n\t"\ "palignr $4, %%xmm0, %%xmm3 \n\t"\ "palignr $4, %%xmm7, %%xmm8 \n\t"\ "palignr $6, %%xmm0, %%xmm2 \n\t"\ "palignr $6, %%xmm7, %%xmm6 \n\t"\ "paddw %%xmm0 ,%%xmm11 \n\t"\ "palignr $8, %%xmm0, %%xmm1 \n\t"\ "palignr $8, %%xmm7, %%xmm0 \n\t"\ "paddw %%xmm12,%%xmm7 \n\t"\ "paddw %%xmm3, %%xmm2 \n\t"\ "paddw %%xmm8, %%xmm6 \n\t"\ "paddw %%xmm4, %%xmm1 \n\t"\ "paddw %%xmm9, %%xmm0 \n\t"\ "psllw $2, %%xmm2 \n\t"\ "psllw $2, %%xmm6 \n\t"\ "psubw %%xmm1, %%xmm2 \n\t"\ "psubw %%xmm0, %%xmm6 \n\t"\ "paddw %%xmm13,%%xmm11 \n\t"\ "paddw %%xmm13,%%xmm7 \n\t"\ "pmullw %%xmm14,%%xmm2 \n\t"\ "pmullw %%xmm14,%%xmm6 \n\t"\ "lddqu (%2), %%xmm3 \n\t"\ "paddw %%xmm11,%%xmm2 \n\t"\ "paddw %%xmm7, %%xmm6 \n\t"\ "psraw $5, %%xmm2 \n\t"\ "psraw $5, %%xmm6 \n\t"\ "packuswb %%xmm2,%%xmm6 \n\t"\ "pavgb %%xmm3, %%xmm6 \n\t"\ OP(%%xmm6, (%1), %%xmm4, dqa)\ "add %5, %0 \n\t"\ "add %5, %1 \n\t"\ "add %4, %2 \n\t"\ "decl %3 \n\t"\ "jg 1b \n\t"\ : "+a"(src), "+c"(dst), "+d"(src2), "+g"(h)\ : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride),\ "m"(ff_pw_5), "m"(ff_pw_16)\ : XMM_CLOBBERS("%xmm0" , "%xmm1" , "%xmm2" , "%xmm3" , \ "%xmm4" , "%xmm5" , "%xmm6" , "%xmm7" , \ "%xmm8" , "%xmm9" , "%xmm10", "%xmm11", \ "%xmm12", "%xmm13", "%xmm14", "%xmm15",)\ "memory"\ );\ } #else // ARCH_X86_64 #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ src += 8*dstStride;\ dst += 8*dstStride;\ src2 += 8*src2Stride;\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ } #endif // ARCH_X86_64 #define QPEL_H264_H_XMM(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ int h=8;\ __asm__ volatile(\ "pxor %%xmm7, %%xmm7 \n\t"\ "movdqa "MANGLE(ff_pw_5)", %%xmm6\n\t"\ "1: \n\t"\ "lddqu -2(%0), %%xmm1 \n\t"\ "movdqa %%xmm1, %%xmm0 \n\t"\ "punpckhbw %%xmm7, %%xmm1 \n\t"\ "punpcklbw %%xmm7, %%xmm0 \n\t"\ "movdqa %%xmm1, %%xmm2 \n\t"\ "movdqa %%xmm1, %%xmm3 \n\t"\ "movdqa %%xmm1, %%xmm4 \n\t"\ "movdqa %%xmm1, %%xmm5 \n\t"\ "palignr $2, %%xmm0, %%xmm4 \n\t"\ "palignr $4, %%xmm0, %%xmm3 \n\t"\ "palignr $6, %%xmm0, %%xmm2 \n\t"\ "palignr $8, %%xmm0, %%xmm1 \n\t"\ "palignr $10,%%xmm0, %%xmm5 \n\t"\ "paddw %%xmm5, %%xmm0 \n\t"\ "paddw %%xmm3, %%xmm2 \n\t"\ "paddw %%xmm4, %%xmm1 \n\t"\ "psllw $2, %%xmm2 \n\t"\ "movq (%2), %%xmm3 \n\t"\ "psubw %%xmm1, %%xmm2 \n\t"\ "paddw "MANGLE(ff_pw_16)", %%xmm0\n\t"\ "pmullw %%xmm6, %%xmm2 \n\t"\ "paddw %%xmm0, %%xmm2 \n\t"\ "psraw $5, %%xmm2 \n\t"\ "packuswb %%xmm2, %%xmm2 \n\t"\ "pavgb %%xmm3, %%xmm2 \n\t"\ OP(%%xmm2, (%1), %%xmm4, q)\ "add %5, %0 \n\t"\ "add %5, %1 \n\t"\ "add %4, %2 \n\t"\ "decl %3 \n\t"\ "jg 1b \n\t"\ : "+a"(src), "+c"(dst), "+d"(src2), "+g"(h)\ : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride)\ : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ "memory"\ );\ }\ QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ \ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ int h=8;\ __asm__ volatile(\ "pxor %%xmm7, %%xmm7 \n\t"\ "movdqa "MANGLE(ff_pw_5)", %%xmm6\n\t"\ "1: \n\t"\ "lddqu -2(%0), %%xmm1 \n\t"\ "movdqa %%xmm1, %%xmm0 \n\t"\ "punpckhbw %%xmm7, %%xmm1 \n\t"\ "punpcklbw %%xmm7, %%xmm0 \n\t"\ "movdqa %%xmm1, %%xmm2 \n\t"\ "movdqa %%xmm1, %%xmm3 \n\t"\ "movdqa %%xmm1, %%xmm4 \n\t"\ "movdqa %%xmm1, %%xmm5 \n\t"\ "palignr $2, %%xmm0, %%xmm4 \n\t"\ "palignr $4, %%xmm0, %%xmm3 \n\t"\ "palignr $6, %%xmm0, %%xmm2 \n\t"\ "palignr $8, %%xmm0, %%xmm1 \n\t"\ "palignr $10,%%xmm0, %%xmm5 \n\t"\ "paddw %%xmm5, %%xmm0 \n\t"\ "paddw %%xmm3, %%xmm2 \n\t"\ "paddw %%xmm4, %%xmm1 \n\t"\ "psllw $2, %%xmm2 \n\t"\ "psubw %%xmm1, %%xmm2 \n\t"\ "paddw "MANGLE(ff_pw_16)", %%xmm0\n\t"\ "pmullw %%xmm6, %%xmm2 \n\t"\ "paddw %%xmm0, %%xmm2 \n\t"\ "psraw $5, %%xmm2 \n\t"\ "packuswb %%xmm2, %%xmm2 \n\t"\ OP(%%xmm2, (%1), %%xmm4, q)\ "add %3, %0 \n\t"\ "add %4, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ : "D"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ "memory"\ );\ }\ static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ src += 8*srcStride;\ dst += 8*dstStride;\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ }\ #define QPEL_H264_V_XMM(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ src -= 2*srcStride;\ \ __asm__ volatile(\ "pxor %%xmm7, %%xmm7 \n\t"\ "movq (%0), %%xmm0 \n\t"\ "add %2, %0 \n\t"\ "movq (%0), %%xmm1 \n\t"\ "add %2, %0 \n\t"\ "movq (%0), %%xmm2 \n\t"\ "add %2, %0 \n\t"\ "movq (%0), %%xmm3 \n\t"\ "add %2, %0 \n\t"\ "movq (%0), %%xmm4 \n\t"\ "add %2, %0 \n\t"\ "punpcklbw %%xmm7, %%xmm0 \n\t"\ "punpcklbw %%xmm7, %%xmm1 \n\t"\ "punpcklbw %%xmm7, %%xmm2 \n\t"\ "punpcklbw %%xmm7, %%xmm3 \n\t"\ "punpcklbw %%xmm7, %%xmm4 \n\t"\ QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\ QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\ QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ "cmpl $16, %4 \n\t"\ "jne 2f \n\t"\ QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\ QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\ QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ "2: \n\t"\ \ : "+a"(src), "+c"(dst)\ - : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\ + : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\ : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ "memory"\ );\ }\ static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\ }\ static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ } static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){ int w = (size+8)>>3; src -= 2*srcStride+2; while(w--){ __asm__ volatile( "pxor %%xmm7, %%xmm7 \n\t" "movq (%0), %%xmm0 \n\t" "add %2, %0 \n\t" "movq (%0), %%xmm1 \n\t" "add %2, %0 \n\t" "movq (%0), %%xmm2 \n\t" "add %2, %0 \n\t" "movq (%0), %%xmm3 \n\t" "add %2, %0 \n\t" "movq (%0), %%xmm4 \n\t" "add %2, %0 \n\t" "punpcklbw %%xmm7, %%xmm0 \n\t" "punpcklbw %%xmm7, %%xmm1 \n\t" "punpcklbw %%xmm7, %%xmm2 \n\t" "punpcklbw %%xmm7, %%xmm3 \n\t" "punpcklbw %%xmm7, %%xmm4 \n\t" QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 0*48) QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 1*48) QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 2*48) QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 3*48) QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 4*48) QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 5*48) QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 6*48) QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 7*48) "cmpl $16, %3 \n\t" "jne 2f \n\t" QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 8*48) QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 9*48) QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 10*48) QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 11*48) QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 12*48) QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 13*48) QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 14*48) QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 15*48) "2: \n\t" : "+a"(src) - : "c"(tmp), "S"((x86_reg)srcStride), "g"(size) + : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size) : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7",) "memory" ); tmp += 8; src += 8 - (size+5)*srcStride; } } #define QPEL_H264_HV2_XMM(OPNAME, OP, MMX)\ static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\ int h = size;\ if(size == 16){\ __asm__ volatile(\ "1: \n\t"\ "movdqa 32(%0), %%xmm4 \n\t"\ "movdqa 16(%0), %%xmm5 \n\t"\ "movdqa (%0), %%xmm7 \n\t"\ "movdqa %%xmm4, %%xmm3 \n\t"\ "movdqa %%xmm4, %%xmm2 \n\t"\ "movdqa %%xmm4, %%xmm1 \n\t"\ "movdqa %%xmm4, %%xmm0 \n\t"\ "palignr $10, %%xmm5, %%xmm0 \n\t"\ "palignr $8, %%xmm5, %%xmm1 \n\t"\ "palignr $6, %%xmm5, %%xmm2 \n\t"\ "palignr $4, %%xmm5, %%xmm3 \n\t"\ "palignr $2, %%xmm5, %%xmm4 \n\t"\ "paddw %%xmm5, %%xmm0 \n\t"\ "paddw %%xmm4, %%xmm1 \n\t"\ "paddw %%xmm3, %%xmm2 \n\t"\ "movdqa %%xmm5, %%xmm6 \n\t"\ "movdqa %%xmm5, %%xmm4 \n\t"\ "movdqa %%xmm5, %%xmm3 \n\t"\ "palignr $8, %%xmm7, %%xmm4 \n\t"\ "palignr $2, %%xmm7, %%xmm6 \n\t"\ "palignr $10, %%xmm7, %%xmm3 \n\t"\ "paddw %%xmm6, %%xmm4 \n\t"\ "movdqa %%xmm5, %%xmm6 \n\t"\ "palignr $6, %%xmm7, %%xmm5 \n\t"\ "palignr $4, %%xmm7, %%xmm6 \n\t"\ "paddw %%xmm7, %%xmm3 \n\t"\ "paddw %%xmm6, %%xmm5 \n\t"\ \ "psubw %%xmm1, %%xmm0 \n\t"\ "psubw %%xmm4, %%xmm3 \n\t"\ "psraw $2, %%xmm0 \n\t"\ "psraw $2, %%xmm3 \n\t"\ "psubw %%xmm1, %%xmm0 \n\t"\ "psubw %%xmm4, %%xmm3 \n\t"\ "paddw %%xmm2, %%xmm0 \n\t"\ "paddw %%xmm5, %%xmm3 \n\t"\ "psraw $2, %%xmm0 \n\t"\ "psraw $2, %%xmm3 \n\t"\ "paddw %%xmm2, %%xmm0 \n\t"\ "paddw %%xmm5, %%xmm3 \n\t"\ "psraw $6, %%xmm0 \n\t"\ "psraw $6, %%xmm3 \n\t"\ "packuswb %%xmm0, %%xmm3 \n\t"\ OP(%%xmm3, (%1), %%xmm7, dqa)\ "add $48, %0 \n\t"\ "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(tmp), "+c"(dst), "+g"(h)\ : "S"((x86_reg)dstStride)\ : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ "memory"\ );\ }else{\ __asm__ volatile(\ "1: \n\t"\ "movdqa 16(%0), %%xmm1 \n\t"\ "movdqa (%0), %%xmm0 \n\t"\ "movdqa %%xmm1, %%xmm2 \n\t"\ "movdqa %%xmm1, %%xmm3 \n\t"\ "movdqa %%xmm1, %%xmm4 \n\t"\ "movdqa %%xmm1, %%xmm5 \n\t"\ "palignr $10, %%xmm0, %%xmm5 \n\t"\ "palignr $8, %%xmm0, %%xmm4 \n\t"\ "palignr $6, %%xmm0, %%xmm3 \n\t"\ "palignr $4, %%xmm0, %%xmm2 \n\t"\ "palignr $2, %%xmm0, %%xmm1 \n\t"\ "paddw %%xmm5, %%xmm0 \n\t"\ "paddw %%xmm4, %%xmm1 \n\t"\ "paddw %%xmm3, %%xmm2 \n\t"\ "psubw %%xmm1, %%xmm0 \n\t"\ "psraw $2, %%xmm0 \n\t"\ "psubw %%xmm1, %%xmm0 \n\t"\ "paddw %%xmm2, %%xmm0 \n\t"\ "psraw $2, %%xmm0 \n\t"\ "paddw %%xmm2, %%xmm0 \n\t"\ "psraw $6, %%xmm0 \n\t"\ "packuswb %%xmm0, %%xmm0 \n\t"\ OP(%%xmm0, (%1), %%xmm7, q)\ "add $48, %0 \n\t"\ "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(tmp), "+c"(dst), "+g"(h)\ : "S"((x86_reg)dstStride)\ : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ "memory"\ );\ }\ } #define QPEL_H264_HV_XMM(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\ put_h264_qpel8or16_hv1_lowpass_sse2(tmp, src, tmpStride, srcStride, size);\ OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\ }\ static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 8);\ }\ static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 16);\ }\ #define put_pixels8_l2_sse2 put_pixels8_l2_mmx2 #define avg_pixels8_l2_sse2 avg_pixels8_l2_mmx2 #define put_pixels16_l2_sse2 put_pixels16_l2_mmx2 #define avg_pixels16_l2_sse2 avg_pixels16_l2_mmx2 #define put_pixels8_l2_ssse3 put_pixels8_l2_mmx2 #define avg_pixels8_l2_ssse3 avg_pixels8_l2_mmx2 #define put_pixels16_l2_ssse3 put_pixels16_l2_mmx2 #define avg_pixels16_l2_ssse3 avg_pixels16_l2_mmx2 #define put_pixels8_l2_shift5_sse2 put_pixels8_l2_shift5_mmx2 #define avg_pixels8_l2_shift5_sse2 avg_pixels8_l2_shift5_mmx2 #define put_pixels16_l2_shift5_sse2 put_pixels16_l2_shift5_mmx2 #define avg_pixels16_l2_shift5_sse2 avg_pixels16_l2_shift5_mmx2 #define put_pixels8_l2_shift5_ssse3 put_pixels8_l2_shift5_mmx2 #define avg_pixels8_l2_shift5_ssse3 avg_pixels8_l2_shift5_mmx2 #define put_pixels16_l2_shift5_ssse3 put_pixels16_l2_shift5_mmx2 #define avg_pixels16_l2_shift5_ssse3 avg_pixels16_l2_shift5_mmx2 #define put_h264_qpel8_h_lowpass_l2_sse2 put_h264_qpel8_h_lowpass_l2_mmx2 #define avg_h264_qpel8_h_lowpass_l2_sse2 avg_h264_qpel8_h_lowpass_l2_mmx2 #define put_h264_qpel16_h_lowpass_l2_sse2 put_h264_qpel16_h_lowpass_l2_mmx2 #define avg_h264_qpel16_h_lowpass_l2_sse2 avg_h264_qpel16_h_lowpass_l2_mmx2 #define put_h264_qpel8_v_lowpass_ssse3 put_h264_qpel8_v_lowpass_sse2 #define avg_h264_qpel8_v_lowpass_ssse3 avg_h264_qpel8_v_lowpass_sse2 #define put_h264_qpel16_v_lowpass_ssse3 put_h264_qpel16_v_lowpass_sse2 #define avg_h264_qpel16_v_lowpass_ssse3 avg_h264_qpel16_v_lowpass_sse2 #define put_h264_qpel8or16_hv2_lowpass_sse2 put_h264_qpel8or16_hv2_lowpass_mmx2 #define avg_h264_qpel8or16_hv2_lowpass_sse2 avg_h264_qpel8or16_hv2_lowpass_mmx2 #define H264_MC(OPNAME, SIZE, MMX, ALIGN) \ H264_MC_C(OPNAME, SIZE, MMX, ALIGN)\ H264_MC_V(OPNAME, SIZE, MMX, ALIGN)\ H264_MC_H(OPNAME, SIZE, MMX, ALIGN)\ H264_MC_HV(OPNAME, SIZE, MMX, ALIGN)\ static void put_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){ put_pixels16_sse2(dst, src, stride, 16); } static void avg_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){ avg_pixels16_sse2(dst, src, stride, 16); } #define put_h264_qpel8_mc00_sse2 put_h264_qpel8_mc00_mmx2 #define avg_h264_qpel8_mc00_sse2 avg_h264_qpel8_mc00_mmx2 #define H264_MC_C(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## pixels ## SIZE ## _ ## MMX(dst, src, stride, SIZE);\ }\ #define H264_MC_H(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\ }\ #define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\ }\ #define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint16_t, temp)[SIZE*(SIZE<8?12:24)];\ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\ }\ #define H264_MC_4816(MMX)\ H264_MC(put_, 4, MMX, 8)\ H264_MC(put_, 8, MMX, 8)\ H264_MC(put_, 16,MMX, 8)\ H264_MC(avg_, 4, MMX, 8)\ H264_MC(avg_, 8, MMX, 8)\ H264_MC(avg_, 16,MMX, 8)\ #define H264_MC_816(QPEL, XMM)\ QPEL(put_, 8, XMM, 16)\ QPEL(put_, 16,XMM, 16)\ QPEL(avg_, 8, XMM, 16)\ QPEL(avg_, 16,XMM, 16)\ #define AVG_3DNOW_OP(a,b,temp, size) \ "mov" #size " " #b ", " #temp " \n\t"\ "pavgusb " #temp ", " #a " \n\t"\ "mov" #size " " #a ", " #b " \n\t" #define AVG_MMX2_OP(a,b,temp, size) \ "mov" #size " " #b ", " #temp " \n\t"\ "pavgb " #temp ", " #a " \n\t"\ "mov" #size " " #a ", " #b " \n\t" #define PAVGB "pavgusb" QPEL_H264(put_, PUT_OP, 3dnow) QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow) #undef PAVGB #define PAVGB "pavgb" QPEL_H264(put_, PUT_OP, mmx2) QPEL_H264(avg_, AVG_MMX2_OP, mmx2) QPEL_H264_V_XMM(put_, PUT_OP, sse2) QPEL_H264_V_XMM(avg_, AVG_MMX2_OP, sse2) QPEL_H264_HV_XMM(put_, PUT_OP, sse2) QPEL_H264_HV_XMM(avg_, AVG_MMX2_OP, sse2) #if HAVE_SSSE3 QPEL_H264_H_XMM(put_, PUT_OP, ssse3) QPEL_H264_H_XMM(avg_, AVG_MMX2_OP, ssse3) QPEL_H264_HV2_XMM(put_, PUT_OP, ssse3) QPEL_H264_HV2_XMM(avg_, AVG_MMX2_OP, ssse3) QPEL_H264_HV_XMM(put_, PUT_OP, ssse3) QPEL_H264_HV_XMM(avg_, AVG_MMX2_OP, ssse3) #endif #undef PAVGB H264_MC_4816(3dnow) H264_MC_4816(mmx2) H264_MC_816(H264_MC_V, sse2) H264_MC_816(H264_MC_HV, sse2) #if HAVE_SSSE3 H264_MC_816(H264_MC_H, ssse3) H264_MC_816(H264_MC_HV, ssse3) #endif diff --git a/libavsequencer/player.c b/libavsequencer/player.c index d07d277..8f269a9 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -9931,1073 +9931,1133 @@ static void init_new_sample(const AVSequencerContext *const avctx, player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &synth->variable[0]; dst_var = (uint16_t *) &player_host_channel->variable[0]; i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; new_player_channel->mixer.pos_one_shoot = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; new_player_channel->auto_pannolo_sweep = player_channel->auto_pannolo_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; new_player_channel->auto_pannolo_depth = player_channel->auto_pannolo_depth; new_player_channel->auto_pannolo_rate = player_channel->auto_pannolo_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; if (player_channel->wait_count[synth_type]--) { exec_synth_done: if ((player_channel->synth_flags & bit_mask) && !(player_channel->kill_count[synth_type]--)) return 0; return 1; } player_channel->wait_count[synth_type] = 0; if ((synth_code_line >= synth->size) || ((int8_t) player_channel->wait_type[synth_type] < 0)) goto exec_synth_done; i = 4 - 1; do { int8_t wait_volume_type; if (((wait_volume_type = ~player_channel->wait_type[synth_type]) >= 0) && (wait_volume_type == i) && (player_channel->wait_line[synth_type] == synth_code_line)) player_channel->wait_type[synth_type] = 0; } while (i--); instruction = synth_code->instruction; dst_var = synth_code->src_dst_var; instruction_data = synth_code->data; if (!instruction && !dst_var && !instruction_data) goto exec_synth_done; src_var = dst_var >> 4; dst_var &= 0x0F; synth_code_line++; if (instruction < 0) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; fx_byte = ~instruction; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = instruction_data + player_channel->variable[src_var]; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, player_channel->host_channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!effects_lut->pre_pattern_func) { instruction_data = player_host_channel->virtual_channel; player_host_channel->virtual_channel = channel; effects_lut->effect_func(avctx, player_host_channel, player_channel, player_channel->host_channel, fx_byte, data_word); player_host_channel->virtual_channel = instruction_data; } player_channel->entry_pos[synth_type] = synth_code_line; } else { uint16_t (**const fx_exec_func)(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint16_t virtual_channel, uint16_t synth_code_line, const int src_var, int dst_var, uint16_t instruction_data, const int synth_type) = (avctx->synth_code_exec_lut ? avctx->synth_code_exec_lut : se_lut); player_channel->entry_pos[synth_type] = fx_exec_func[(uint8_t) instruction](avctx, player_channel, channel, synth_code_line, src_var, dst_var, instruction_data, synth_type); } } while (++synth_count); return 0; } static const int8_t empty_waveform[256]; +/* #define ACCURATE_VOLUMES 1 */ + +#ifdef ACCURATE_VOLUMES +static inline void mulu_128(uint64_t *const result, const uint64_t a, + const uint64_t b) +{ + const uint32_t a_hi = a >> 32; + const uint32_t a_lo = (uint32_t) a; + const uint32_t b_hi = b >> 32; + const uint32_t b_lo = (uint32_t) b; + const uint64_t x1 = (uint64_t) a_lo * b_hi; + uint64_t x2 = (uint64_t) a_hi * b_lo; + const uint64_t x3 = (uint64_t) a_lo * b_lo; + uint64_t x0 = (uint64_t) a_hi * b_hi; + + x2 += x3 >> 32; + x2 += x1; + x0 += (x2 < x1) ? UINT64_C(0x100000000) : 0; + result[0] = x0 + (x2 >> 32); + result[1] = (x2 << 32) + (x3 & UINT64_C(0xFFFFFFFF)); +} + +static inline uint64_t divu_128(const uint64_t *const a, + const uint64_t b) +{ + uint64_t a_hi = a[0]; + uint64_t a_lo = a[1]; + uint64_t result = 0, result_r = 0; + uint16_t i = 128; + + while (i--) { + const uint64_t carry = a_lo >> 63; + const uint64_t carry2 = a_hi >> 63; + + result <<= 1; + a_lo <<= 1; + a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) + result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) + + if (result_r >= b) { + result_r -= b; + result++; + } + } + + return result; +} +#endif + int avseq_playback_handler(AVMixerData *mixer_data) { AVSequencerContext *const avctx = (AVSequencerContext *) mixer_data->opaque; const AVSequencerModule *const module = avctx->player_module; const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; AVSequencerPlayerHostChannel *player_host_channel = avctx->player_host_channel; AVSequencerPlayerChannel *player_channel = avctx->player_channel; const AVSequencerPlayerHook *player_hook; uint16_t channel, virtual_channel; if (!(module && song && player_globals && player_host_channel && player_channel)) return 0; channel = 0; do { if (mixer_data->mixctx->get_channel) mixer_data->mixctx->get_channel(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE) { if (!player_globals->trace_count--) player_globals->trace_count = 0; return 0; } player_hook = avctx->player_hook; if (player_hook && (player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->play_type & AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG) { uint32_t play_time_calc, play_time_advance, play_time_fraction; play_time_calc = ((uint64_t) player_globals->tempo * player_globals->relative_speed) >> 16; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_time_frac += play_time_fraction; play_time_advance += (player_globals->play_time_frac < play_time_fraction); player_globals->play_time += play_time_advance; play_time_calc = player_globals->tempo; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_tics_frac += play_time_fraction; play_time_advance += (player_globals->play_tics_frac < play_time_fraction); player_globals->play_tics += play_time_advance; } channel = 0; do { player_channel = avctx->player_channel + player_host_channel->virtual_channel; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE)) { const AVSequencerTrack *const old_track = player_host_channel->track; - const AVSequencerTrackEffect const *old_effect = player_host_channel->effect; + const AVSequencerTrackEffect *const old_effect = player_host_channel->effect; const uint32_t old_tempo_counter = player_host_channel->tempo_counter; const uint16_t old_row = player_host_channel->row; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE); player_host_channel->track = (const AVSequencerTrack *) player_host_channel->instrument; player_host_channel->effect = NULL; player_host_channel->row = (uint32_t) player_host_channel->sample; player_host_channel->instrument = NULL; player_host_channel->sample = NULL; get_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->tempo_counter = player_host_channel->note_delay; get_note(avctx, player_host_channel, player_channel, channel); run_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->track = old_track; player_host_channel->effect = old_effect; player_host_channel->tempo_counter = old_tempo_counter; player_host_channel->row = old_row; } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) { const uint16_t note = player_host_channel->instr_note; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT; if ((int8_t) note < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } } else { const AVSequencerInstrument *const instrument = player_host_channel->instrument; AVSequencerPlayerChannel *new_player_channel; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, note / 12, note % 12, channel))) player_channel = new_player_channel; player_channel->volume = player_host_channel->sample_note; player_channel->sub_volume = 0; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample = player_host_channel->sample; const uint32_t frequency = (uint32_t) player_host_channel->instrument; uint32_t i; uint16_t virtual_channel; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE; player_host_channel->dct = 0; player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; player_host_channel->finetune = sample->finetune; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *) &virtual_channel); sample = player_host_channel->sample; player_channel->mixer.pos = sample->start_offset; player_channel->mixer.pos_one_shoot = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_host_channel->instrument = NULL; player_channel->sample = sample; player_channel->frequency = frequency; player_channel->volume = player_host_channel->instr_note; player_channel->sub_volume = 0; player_host_channel->instr_note = 0; init_new_instrument(avctx, player_host_channel, player_channel); i = -1; while (++i < module->instruments) { uint16_t smp = -1; if (!(instrument = module->instrument_list[i])) continue; while (++smp < instrument->samples) { if (!(sample = instrument->sample_list[smp])) continue; if (sample == player_channel->sample) { player_host_channel->instrument = instrument; goto instrument_found; } } } instrument_found: player_channel->instrument = player_host_channel->instrument; init_new_sample(avctx, player_host_channel, player_channel); } if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { do { process_row(avctx, player_host_channel, player_channel, channel); get_effects(avctx, player_host_channel, player_channel, channel); if (player_channel->host_channel == channel) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO)) { const int32_t slide_value = player_host_channel->vibrato_slide; player_host_channel->vibrato_slide = 0; player_channel->frequency -= slide_value; } if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO)) { int16_t slide_value = player_host_channel->tremolo_slide; player_host_channel->tremolo_slide = 0; if ((int16_t) (slide_value = (player_channel->volume - slide_value)) < 0) slide_value = 0; if (slide_value > 255) slide_value = 255; player_channel->volume = slide_value; } } } while (get_note(avctx, player_host_channel, player_channel, channel)); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { player_channel = avctx->player_channel + player_host_channel->virtual_channel; run_effects(avctx, player_host_channel, player_channel, channel); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); virtual_channel = 0; channel = 0; player_channel = avctx->player_channel; do { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { const AVSequencerSample *sample; AVSequencerPlayerEnvelope *player_envelope; +#ifdef ACCURATE_VOLUMES + uint64_t tmp_128[2]; +#endif uint32_t frequency, host_volume, virtual_volume; uint32_t auto_vibrato_depth, auto_vibrato_count; int32_t auto_vibrato_value; uint16_t flags, slide_envelope_value; int16_t panning, abs_panning, panning_envelope_value; player_host_channel = avctx->player_host_channel + player_channel->host_channel; player_envelope = &player_channel->vol_env; if (player_envelope->tempo) { const uint16_t volume = run_envelope(avctx, player_envelope, 1, -0x8000); if (!player_envelope->tempo) { if (!(volume >> 8)) goto turn_note_off; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } run_envelope(avctx, &player_channel->pan_env, 1, 0); slide_envelope_value = run_envelope(avctx, &player_channel->slide_env, 1, 0); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency += player_channel->slide_env_freq; if ((frequency = player_channel->frequency)) { if ((int16_t) slide_envelope_value < 0) { slide_envelope_value = -slide_envelope_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) frequency = linear_slide_down(avctx, player_channel, frequency, slide_envelope_value); else frequency = amiga_slide_down(player_channel, frequency, slide_envelope_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) { frequency = linear_slide_up(avctx, player_channel, frequency, slide_envelope_value); } else { frequency = amiga_slide_up(player_channel, frequency, slide_envelope_value); } player_channel->slide_env_freq += old_frequency - frequency; } } else { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_envelope_frequency, old_frequency; int16_t octave, note; const int16_t slide_note = (int16_t) slide_envelope_value >> 8; int32_t finetune = slide_envelope_value & 0xFF; octave = slide_note / 12; note = slide_note % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (finetune * (int32_t) next_frequency) >> 8; slide_envelope_frequency = player_channel->slide_env_freq; old_frequency = player_channel->frequency; slide_envelope_frequency += old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_envelope_frequency) >> (24 - octave); player_channel->slide_env_freq += old_frequency - frequency; } if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_FADING) { int32_t fade_out = (uint32_t) player_channel->fade_out_count; if ((fade_out -= (int32_t) player_channel->fade_out) <= 0) goto turn_note_off; player_channel->fade_out_count = fade_out; } auto_vibrato_value = run_envelope(avctx, &player_channel->auto_vib_env, player_channel->auto_vibrato_rate, 0); auto_vibrato_depth = player_channel->auto_vibrato_depth << 8; auto_vibrato_count = (uint32_t) player_channel->auto_vibrato_count + player_channel->auto_vibrato_sweep; if (auto_vibrato_count > auto_vibrato_depth) auto_vibrato_count = auto_vibrato_depth; player_channel->auto_vibrato_count = auto_vibrato_count; auto_vibrato_count >>= 8; if ((auto_vibrato_value *= (int32_t) -auto_vibrato_count)) { uint32_t old_frequency = player_channel->frequency; auto_vibrato_value >>= 7 - 2; player_channel->frequency -= player_channel->auto_vibrato_freq; if ((frequency = player_channel->frequency)) { if (auto_vibrato_value < 0) { auto_vibrato_value = -auto_vibrato_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) frequency = linear_slide_up(avctx, player_channel, frequency, auto_vibrato_value); else frequency = amiga_slide_up(player_channel, frequency, auto_vibrato_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) { frequency = linear_slide_down(avctx, player_channel, frequency, auto_vibrato_value); } else { frequency = amiga_slide_down(player_channel, frequency, auto_vibrato_value); } player_channel->auto_vibrato_freq -= old_frequency - frequency; } } if ((sample = player_channel->sample) && sample->synth) { if (!execute_synth(avctx, player_host_channel, player_channel, channel, 0)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 1)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 2)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 3)) goto turn_note_off; } if ((!player_channel->mixer.data || !player_channel->mixer.bits_per_sample) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { player_channel->mixer.pos = 0; player_channel->mixer.pos_one_shoot = 0; player_channel->mixer.len = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.data = (int16_t *) &empty_waveform; player_channel->mixer.repeat_start = 0; player_channel->mixer.repeat_length = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.repeat_count = 0; player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = (sizeof (empty_waveform[0]) * 8); player_channel->mixer.flags = AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } frequency = player_channel->frequency; if (sample) { if (frequency < sample->rate_min) frequency = sample->rate_min; if (frequency > sample->rate_max) frequency = sample->rate_max; } if (!(player_channel->frequency = frequency)) { turn_note_off: player_channel->mixer.flags = 0; goto not_calculate_no_playing; } if (!(player_channel->mixer.rate = ((uint64_t) frequency * player_globals->relative_pitch) >> 16)) goto turn_note_off; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_GLOBAL_NEW_ONLY)) { player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; } host_volume = player_channel->volume; player_host_channel->virtual_channels++; virtual_channel++; if (!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) && (player_host_channel->virtual_channel == channel) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC) && (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON))) host_volume = 0; +#ifdef ACCURATE_VOLUMES host_volume *= (uint16_t) player_host_channel->track_volume * (uint16_t) player_channel->instr_volume; - virtual_volume = (((uint16_t) player_channel->vol_env.value >> 8) * (uint16_t) player_channel->global_volume) * (uint16_t) player_channel->fade_out_count; + virtual_volume = (uint32_t) player_channel->fade_out_count * ((((uint16_t) player_channel->vol_env.value >> 8U) * (uint16_t) player_channel->global_volume)); + mulu_128(tmp_128, host_volume, virtual_volume); + player_channel->mixer.volume = player_channel->final_volume = (uint8_t) divu_128(tmp_128, UINT64_C(70660093200890625)); /* / (255ULL*255ULL*255ULL*255ULL*65535ULL*255ULL) */ +#else + host_volume *= (uint16_t) player_host_channel->track_volume * (uint16_t) player_channel->instr_volume; + virtual_volume = (uint32_t) player_channel->fade_out_count * ((((uint16_t) player_channel->vol_env.value >> 8U) * (uint16_t) player_channel->global_volume)); player_channel->mixer.volume = player_channel->final_volume = ((uint64_t) host_volume * virtual_volume) / UINT64_C(70660093200890625); /* / (255ULL*255ULL*255ULL*255ULL*65535ULL*255ULL) */ +#endif + flags = 0; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND; player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning = (uint8_t) player_channel->panning; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) { panning = (uint8_t) player_host_channel->track_panning; flags = 0; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN)) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; } player_channel->flags |= flags; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) player_channel->mixer.flags |= flags; if (panning == 255) panning++; panning_envelope_value = panning; if ((int16_t) (panning = (128 - panning)) < 0) panning = -panning; abs_panning = 128 - panning; panning = player_channel->pan_env.value >> 8; if (panning == 127) panning++; panning = 128 - (((panning * abs_panning) >> 7) + panning_envelope_value); abs_panning = (uint8_t) player_host_channel->channel_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning_envelope_value = abs_panning = ((panning * abs_panning) >> 7) + 128; if (panning_envelope_value > 255) panning_envelope_value = 255; player_channel->final_panning = panning_envelope_value; panning = 128; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_GLOBAL_SUR_PAN) player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning -= abs_panning; abs_panning = (uint8_t) player_channel->global_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning = ((panning * abs_panning) >> 7) + 128; if (panning == 256) panning--; } player_channel->mixer.panning = panning; if (mixer_data->mixctx->set_channel_volume_panning_pitch) mixer_data->mixctx->set_channel_volume_panning_pitch(mixer_data, &player_channel->mixer, channel); } not_calculate_no_playing: if (mixer_data->mixctx->set_channel_position_repeat_flags) mixer_data->mixctx->set_channel_position_repeat_flags(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); player_globals->channels = virtual_channel; if (virtual_channel > player_globals->max_channels) player_globals->max_channels = virtual_channel; channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END)) goto check_song_end_done; player_host_channel++; } while (++channel < song->channels); player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END; check_song_end_done: if (player_hook && !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END) { player_host_channel = avctx->player_host_channel; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END) { AVSequencerOrderList *order_list = song->order_list; channel = song->channels; do { AVSequencerOrderData *order_data; uint32_t i = -1; if (player_host_channel->tempo) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; while (++i < order_list->orders) { if ((order_data = order_list->order_data[i]) && (order_data != player_host_channel->order)) order_data->played = 0; } order_list++; player_host_channel++; } while (--channel); } } return 0; }
BastyCDGS/ffmpeg-soc
ed46d8417a37d98a8110dd25c4645363fcb07251
Fixed portamento memory handling for fine portamento once up and down and clarified variable name.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 4fc7c59..d07d277 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -1,900 +1,900 @@ /* * Sequencer main playback handler * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer main playback handler. */ #include <stddef.h> #include <string.h> #include "libavutil/intreadwrite.h" #include "libavsequencer/avsequencer.h" #include "libavsequencer/player.h" #define AVSEQ_RANDOM_CONST -1153374675 #define AVSEQ_SLIDE_CONST (UINT64_C(0x100000000)*UINT64_C(8363*1712*4)) #define ASSIGN_INSTRUMENT_ENVELOPE(env_type) \ static const AVSequencerEnvelope *assign_##env_type##_envelope(const AVSequencerContext *const avctx, \ const AVSequencerInstrument *const instrument, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const AVSequencerEnvelope **envelope, \ AVSequencerPlayerEnvelope **player_envelope) ASSIGN_INSTRUMENT_ENVELOPE(volume) { if (instrument) *envelope = instrument->volume_env; *player_envelope = &player_channel->vol_env; return player_host_channel->prev_volume_env; } ASSIGN_INSTRUMENT_ENVELOPE(panning) { if (instrument) *envelope = instrument->panning_env; *player_envelope = &player_channel->pan_env; return player_host_channel->prev_panning_env; } ASSIGN_INSTRUMENT_ENVELOPE(slide) { if (instrument) *envelope = instrument->slide_env; *player_envelope = &player_channel->slide_env; return player_host_channel->prev_slide_env; } ASSIGN_INSTRUMENT_ENVELOPE(vibrato) { if (instrument) *envelope = instrument->vibrato_env; *player_envelope = &player_host_channel->vibrato_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &player_host_channel->tremolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &player_host_channel->pannolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(channolo) { if (instrument) *envelope = instrument->channolo_env; *player_envelope = &player_host_channel->channolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(spenolo) { if (instrument) *envelope = instrument->spenolo_env; *player_envelope = &avctx->player_globals->spenolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(track_tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &player_host_channel->track_trem_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(track_pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &player_host_channel->track_pan_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(global_tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &avctx->player_globals->tremolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(global_pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &avctx->player_globals->pannolo_env; return (*player_envelope)->envelope; } #define ASSIGN_SAMPLE_ENVELOPE(env_type) \ static const AVSequencerEnvelope *assign_##env_type##_envelope(const AVSequencerSample *const sample, \ AVSequencerPlayerChannel *const player_channel, \ AVSequencerPlayerEnvelope **player_envelope) \ ASSIGN_SAMPLE_ENVELOPE(auto_vibrato) { *player_envelope = &player_channel->auto_vib_env; return sample->auto_vibrato_env; } ASSIGN_SAMPLE_ENVELOPE(auto_tremolo) { *player_envelope = &player_channel->auto_trem_env; return sample->auto_tremolo_env; } ASSIGN_SAMPLE_ENVELOPE(auto_pannolo) { *player_envelope = &player_channel->auto_pan_env; return sample->auto_pannolo_env; } ASSIGN_INSTRUMENT_ENVELOPE(resonance) { if (instrument) *envelope = instrument->resonance_env; *player_envelope = &player_channel->resonance_env; return player_host_channel->prev_resonance_env; } #define USE_ENVELOPE(env_type) \ static AVSequencerPlayerEnvelope *use_##env_type##_envelope(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel) USE_ENVELOPE(volume) { return &player_channel->vol_env; } USE_ENVELOPE(panning) { return &player_channel->pan_env; } USE_ENVELOPE(slide) { return &player_channel->slide_env; } USE_ENVELOPE(vibrato) { return &player_host_channel->vibrato_env; } USE_ENVELOPE(tremolo) { return &player_host_channel->tremolo_env; } USE_ENVELOPE(pannolo) { return &player_host_channel->pannolo_env; } USE_ENVELOPE(channolo) { return &player_host_channel->channolo_env; } USE_ENVELOPE(spenolo) { return &avctx->player_globals->spenolo_env; } USE_ENVELOPE(auto_vibrato) { return &player_channel->auto_vib_env; } USE_ENVELOPE(auto_tremolo) { return &player_channel->auto_trem_env; } USE_ENVELOPE(auto_pannolo) { return &player_channel->auto_pan_env; } USE_ENVELOPE(track_tremolo) { return &player_host_channel->track_trem_env; } USE_ENVELOPE(track_pannolo) { return &player_host_channel->track_pan_env; } USE_ENVELOPE(global_tremolo) { return &avctx->player_globals->tremolo_env; } USE_ENVELOPE(global_pannolo) { return &avctx->player_globals->pannolo_env; } USE_ENVELOPE(arpeggio) { return &player_host_channel->arpepggio_env; } USE_ENVELOPE(resonance) { return &player_channel->resonance_env; } #define PRESET_EFFECT(fx_type) \ static void preset_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t data_word) PRESET_EFFECT(tone_portamento) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA; } PRESET_EFFECT(vibrato) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO; } PRESET_EFFECT(note_delay) { if ((player_host_channel->note_delay = data_word)) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = player_host_channel->note_delay; } } } PRESET_EFFECT(tremolo) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO; } PRESET_EFFECT(set_transpose) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE; player_host_channel->transpose = data_word >> 8; player_host_channel->trans_finetune = data_word; } static const int32_t portamento_mask[8] = { 0, 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE }; static const int32_t portamento_trigger_mask[6] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, - AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, - AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN, - AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN + AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN, + AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, + AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN }; #define CHECK_EFFECT(fx_type) \ static void check_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t *const fx_byte, \ uint16_t *const data_word, \ uint16_t *const flags) CHECK_EFFECT(portamento) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE); player_host_channel->fine_slide_flags |= portamento_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { if ((*fx_byte <= AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN) && !(player_host_channel->fine_slide_flags & (AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE))) goto trigger_portamento_done; *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE) *fx_byte += AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES) && (*fx_byte > AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN)) { - const uint16_t mask_volume_fx = *fx_byte; + const uint16_t mask_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; *fx_byte &= -2; - if (player_host_channel->fine_slide_flags & portamento_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN - 1)]) + if (player_host_channel->fine_slide_flags & portamento_trigger_mask[(mask_fx - AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN - 1)]) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; } trigger_portamento_done: *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(tone_portamento) { } CHECK_EFFECT(note_slide) { uint8_t note_slide_type; if (!(note_slide_type = (*data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; if (note_slide_type & 0xF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE }; static const int32_t volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN }; CHECK_EFFECT(volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE); player_host_channel->fine_slide_flags |= volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; *fx_byte &= -2; if (volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(volume_slide_to) { if ((*data_word >> 8) == 0xFF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t track_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE }; static const int32_t track_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN }; CHECK_EFFECT(track_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE); player_host_channel->fine_slide_flags |= track_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; *fx_byte &= -2; if (track_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE }; static const int32_t panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT }; CHECK_EFFECT(panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE); player_host_channel->fine_slide_flags |= panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; *fx_byte &= -2; if (panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t track_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE }; static const int32_t track_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT }; CHECK_EFFECT(track_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE); player_host_channel->fine_slide_flags |= track_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; *fx_byte &= -2; if (track_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t speed_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE }; static const int32_t speed_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER }; CHECK_EFFECT(speed_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE); player_host_channel->fine_slide_flags |= speed_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; *fx_byte &= -2; if (speed_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(channel_control) { } static const int32_t global_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE }; static const int32_t global_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN }; CHECK_EFFECT(global_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE); player_host_channel->fine_slide_flags |= global_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t global_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE }; static const int32_t global_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT }; CHECK_EFFECT(global_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE); player_host_channel->fine_slide_flags |= global_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static int16_t step_envelope(AVSequencerContext *const avctx, AVSequencerPlayerEnvelope *const player_envelope, const int16_t *const envelope_data, uint16_t envelope_pos, const uint16_t tempo_multiplier, const int16_t value_adjustment) { uint32_t seed, randomize_value; const uint16_t envelope_restart = player_envelope->start; int16_t value; value = envelope_data[envelope_pos]; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM) { avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; randomize_value = ((int32_t) player_envelope->value_max - (int32_t) player_envelope->value_min) + 1; value = ((uint64_t) seed * randomize_value) >> 32; value += player_envelope->value_min; } value += value_adjustment; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS) { if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over_back; for (;;) { check_back_envelope_loop: if (envelope_pos <= envelope_restart) break; loop_envelope_over_back: if (envelope_restart == player_envelope->end) goto run_envelope_check_pingpong_wait; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + envelope_restart; if (envelope_pos < envelope_restart) goto check_envelope_loop; goto loop_envelope_over; } else { envelope_pos += player_envelope->end - envelope_restart; } } } else { if (envelope_pos < tempo_multiplier) player_envelope->tempo = 0; envelope_pos -= tempo_multiplier; } } else if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over; for (;;) { check_envelope_loop: if (envelope_pos <= player_envelope->end) break; loop_envelope_over: if (envelope_restart == player_envelope->end) { run_envelope_check_pingpong_wait: envelope_pos = envelope_restart; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; break; } if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + player_envelope->end; if (envelope_pos < player_envelope->end) goto check_back_envelope_loop; goto loop_envelope_over_back; } else { envelope_pos += envelope_restart - player_envelope->end; } } } else { envelope_pos += tempo_multiplier; if ((envelope_pos < tempo_multiplier) || (envelope_pos > player_envelope->end)) player_envelope->tempo = 0; } player_envelope->pos = envelope_pos; if ((player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD) && !(player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM)) value = envelope_data[envelope_pos] + value_adjustment; return value; } static void set_envelope(AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope *const envelope, uint16_t envelope_pos) { const AVSequencerEnvelope *instrument_envelope; uint8_t envelope_flags; uint16_t envelope_loop_start, envelope_loop_end; if (!(instrument_envelope = envelope->envelope)) return; envelope_flags = AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING; envelope_loop_start = envelope->loop_start; envelope_loop_end = envelope->loop_end; if ((envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_SUSTAIN) && !(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN)) { envelope_loop_start = envelope->sustain_start; envelope_loop_end = envelope->sustain_end; } else if (!(envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_LOOP)) { envelope_flags = 0; envelope_loop_end = instrument_envelope->points - 1; } if (envelope_loop_start > envelope_loop_end) envelope_loop_start = envelope_loop_end; if (envelope_pos > envelope_loop_end) envelope_pos = envelope_loop_end; envelope->pos = envelope_pos; envelope->start = envelope_loop_start; envelope->end = envelope_loop_end; envelope->flags = envelope_flags;
BastyCDGS/ffmpeg-soc
065cba7ae97c19e4702e652ccf140e28c8923a42
Optimized null, low and high quality mixers of AVSequencer in initial mixing call.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 15eab6d..ccb1a62 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -6685,627 +6685,615 @@ static av_cold uint32_t set_rate(AVMixerData *const mixer_data, if (hq_mixer_data->mix_rate != old_mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = old_mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; update_sample_filter(hq_mixer_data, channel_info, &channel_info->current); update_sample_filter(hq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { int32_t *volume_lut = hq_mixer_data->volume_lut; int64_t volume_mult = 0; int32_t volume_div = channels << 8; uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = hq_mixer_data->current_left; uint32_t current_left_frac = hq_mixer_data->current_left_frac; uint32_t buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; - - if (current_left_frac < hq_mixer_data->pass_len_frac) - current_left++; + current_left = hq_mixer_data->pass_len + (current_left_frac < hq_mixer_data->pass_len_frac); } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = hq_mixer_data->current_left; uint32_t current_left_frac = hq_mixer_data->current_left_frac; uint32_t buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(hq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; - - if (current_left_frac < hq_mixer_data->pass_len_frac) - current_left++; + current_left = hq_mixer_data->pass_len + (current_left_frac < hq_mixer_data->pass_len_frac); } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext high_quality_mixer = { .av_class = &avseq_high_quality_mixer_class, .name = "High quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for quality and supports advanced interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_HIGH_QUALITY_MIXER */ diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 5f8c0fd..959bdfc 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -5183,627 +5183,615 @@ static av_cold uint32_t set_rate(AVMixerData *const mixer_data, lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != old_mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = old_mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; update_sample_filter(lq_mixer_data, channel_info, &channel_info->current); update_sample_filter(lq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = lq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { int32_t *volume_lut = lq_mixer_data->volume_lut; int64_t volume_mult = 0; int32_t volume_div = channels << 8; uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(lq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, 4095, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, 4095, 0); } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = lq_mixer_data->current_left; uint32_t current_left_frac = lq_mixer_data->current_left_frac; uint32_t buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; - - if (current_left_frac < lq_mixer_data->pass_len_frac) - current_left++; + current_left = lq_mixer_data->pass_len + (current_left_frac < lq_mixer_data->pass_len_frac); } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = lq_mixer_data->current_left; uint32_t current_left_frac = lq_mixer_data->current_left_frac; uint32_t buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(lq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; - - if (current_left_frac < lq_mixer_data->pass_len_frac) - current_left++; + current_left = lq_mixer_data->pass_len + (current_left_frac < lq_mixer_data->pass_len_frac); } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_LOW_QUALITY_MIXER */ diff --git a/libavsequencer/null_mixer.c b/libavsequencer/null_mixer.c index ececbb7..4c80d64 100644 --- a/libavsequencer/null_mixer.c +++ b/libavsequencer/null_mixer.c @@ -611,618 +611,606 @@ static av_cold uint32_t set_rate(AVMixerData *const mixer_data, null_mixer_data->mixer_data.rate = mix_rate; null_mixer_data->mixer_data.channels_out = channels; if ((null_mixer_data->mixer_data.mix_buf_size * null_mixer_data->channels_out) != (buf_size * channels)) { int32_t *buf = null_mixer_data->mixer_data.mix_buf; const uint32_t mix_buf_mem_size = (buf_size * channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(null_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output channel data.\n"); return null_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); null_mixer_data->mixer_data.mix_buf = buf; null_mixer_data->mixer_data.mix_buf_size = buf_size; } null_mixer_data->channels_out = channels; if (null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (null_mixer_data->mix_rate != old_mix_rate) { AV_NULLMixerChannelInfo *channel_info = null_mixer_data->channel_info; uint16_t i; null_mixer_data->mix_rate = old_mix_rate; null_mixer_data->mix_rate_frac = mix_rate_frac; if (null_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, null_mixer_data->mixer_data.tempo); for (i = null_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *channel_info = NULL; AV_NULLMixerChannelInfo *const old_channel_info = null_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = null_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_NULLMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(null_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } null_mixer_data->mixer_data.volume_boost = amplify; null_mixer_data->mixer_data.volume_left = left_volume; null_mixer_data->mixer_data.volume_right = right_volume; null_mixer_data->mixer_data.channels_in = channels; if (old_channels && channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_NULLMixerChannelInfo)); null_mixer_data->channel_info = channel_info; null_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { channel_info->current.filter_cutoff = 4095; channel_info->next.filter_cutoff = 4095; channel_info++; } av_free(old_channel_info); } channel_info = null_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(null_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; const AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_cutoff = 4095; channel_block->filter_damping = 0; channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_cutoff = 4095; channel_block->filter_damping = 0; } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; const AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel_current->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel_current->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel_next->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel_next->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = null_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = null_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if ((channel_info->current.filter_cutoff = mixer_channel->filter_cutoff) > 4095) channel_info->current.filter_cutoff = 4095; if ((channel_info->current.filter_damping = mixer_channel->filter_damping) > 4095) channel_info->current.filter_damping = 4095; } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; if (!(null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = null_mixer_data->current_left; uint32_t current_left_frac = null_mixer_data->current_left_frac; uint32_t buf_size = null_mixer_data->mixer_data.mix_buf_size; while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample(null_mixer_data, mix_len); } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = null_mixer_data->pass_len; current_left_frac += null_mixer_data->pass_len_frac; - - if (current_left_frac < null_mixer_data->pass_len_frac) - current_left++; + current_left = null_mixer_data->pass_len + (current_left_frac < null_mixer_data->pass_len_frac); } null_mixer_data->current_left = current_left; null_mixer_data->current_left_frac = current_left_frac; } } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; if (!(null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { uint32_t current_left = null_mixer_data->current_left; uint32_t current_left_frac = null_mixer_data->current_left_frac; uint32_t buf_size = null_mixer_data->mixer_data.mix_buf_size; while (buf_size) { if (current_left) { - uint32_t mix_len = buf_size; - - if (buf_size > current_left) - mix_len = current_left; + const uint32_t mix_len = (buf_size > current_left) ? current_left : buf_size; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(null_mixer_data, mix_len, first_channel, last_channel); } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); - current_left = null_mixer_data->pass_len; current_left_frac += null_mixer_data->pass_len_frac; - - if (current_left_frac < null_mixer_data->pass_len_frac) - current_left++; + current_left = null_mixer_data->pass_len + (current_left_frac < null_mixer_data->pass_len_frac); } null_mixer_data->current_left = current_left; null_mixer_data->current_left_frac = current_left_frac; } } AVMixerContext null_mixer = { .av_class = &avseq_null_mixer_class, .name = "Null mixer", .description = NULL_IF_CONFIG_SMALL("Always outputs silence and simulates basic mixing"), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_NULL_MIXER */
BastyCDGS/ffmpeg-soc
1afabda395a4e1536a9716e402f5dda60079e646
Fixed some nits in low and high quality mixer apply (resonance) filter code of AVSequencer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 92b82f5..15eab6d 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1,671 +1,669 @@ /* * Sequencer high quality integer mixer * Copyright (c) 2011 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer high quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_HQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_HQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_HQMixerData; typedef struct AV_HQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t offset_one_shoot; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint64_t mult_left_volume; uint64_t mult_right_volume; uint32_t div_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint16_t filter_cutoff; uint16_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; int32_t prev_sample; int32_t curr_sample; int32_t next_sample; int32_t prev_sample_r; int32_t curr_sample_r; int32_t next_sample_r; int mix_right; } AV_HQMixerChannelInfo; #if CONFIG_HIGH_QUALITY_MIXER static const char *high_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_high_quality_mixer_class = { "AVSequencer High Quality Mixer", high_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_HQMixerChannelInfo *channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; const int64_t c1 = channel_block->filter_c1; const int64_t c2 = channel_block->filter_c2; const int64_t c3 = channel_block->filter_c3; int32_t o1 = channel_info->filter_tmp2; int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = ((c1 * src_buf[0]) + (c2 * o2) + (c3 * o1)) >> 24; mix_buf[1] += o4 = ((c1 * src_buf[1]) + (c2 * o3) + (c3 * o2)) >> 24; mix_buf[2] += o1 = ((c1 * src_buf[2]) + (c2 * o4) + (c3 * o3)) >> 24; mix_buf[3] += o2 = ((c1 * src_buf[3]) + (c2 * o1) + (c3 * o4)) >> 24; - - src_buf += 4; - mix_buf += 4; + src_buf += 4; + mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = ((c1 * *src_buf++) + (c2 * o2) + (c3 * o1)) >> 24; - - o1 = o2; - o2 = o3; + o1 = o2; + o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset_one_shoot += (offset > channel_info->current.offset) ? (offset - channel_info->current.offset) : (channel_info->current.offset - offset); if (channel_info->current.offset_one_shoot >= channel_info->current.len) { channel_info->current.offset_one_shoot = channel_info->current.len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index b439978..5f8c0fd 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -1,661 +1,659 @@ /* * Sequencer low quality integer mixer * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer low quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_LQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_LQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_LQMixerData; typedef struct AV_LQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t offset_one_shoot; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint16_t filter_cutoff; uint16_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; } AV_LQMixerChannelInfo; #if CONFIG_LOW_QUALITY_MIXER static const char *low_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_low_quality_mixer_class = { "AVSequencer Low Quality Mixer", low_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_LQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; const int64_t c1 = channel_block->filter_c1; const int64_t c2 = channel_block->filter_c2; const int64_t c3 = channel_block->filter_c3; int32_t o1 = channel_info->filter_tmp2; int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = ((c1 * src_buf[0]) + (c2 * o2) + (c3 * o1)) >> 24; mix_buf[1] += o4 = ((c1 * src_buf[1]) + (c2 * o3) + (c3 * o2)) >> 24; mix_buf[2] += o1 = ((c1 * src_buf[2]) + (c2 * o4) + (c3 * o3)) >> 24; mix_buf[3] += o2 = ((c1 * src_buf[3]) + (c2 * o1) + (c3 * o4)) >> 24; - - src_buf += 4; - mix_buf += 4; + src_buf += 4; + mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = ((c1 * *src_buf++) + (c2 * o2) + (c3 * o1)) >> 24; - - o1 = o2; - o2 = o3; + o1 = o2; + o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset_one_shoot += (offset > channel_info->current.offset) ? (offset - channel_info->current.offset) : (channel_info->current.offset - offset); if (channel_info->current.offset_one_shoot >= channel_info->current.len) { channel_info->current.offset_one_shoot = channel_info->current.len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock));
BastyCDGS/ffmpeg-soc
7e26df0577b2cc2a0fd9c0ec63b54f82cf0d695e
Constify and optimize of low and high quality mixer (resonance) filter.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 38d8046..92b82f5 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1,668 +1,668 @@ /* * Sequencer high quality integer mixer * Copyright (c) 2011 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer high quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_HQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_HQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_HQMixerData; typedef struct AV_HQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t offset_one_shoot; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint64_t mult_left_volume; uint64_t mult_right_volume; uint32_t div_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint16_t filter_cutoff; uint16_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; int32_t prev_sample; int32_t curr_sample; int32_t next_sample; int32_t prev_sample_r; int32_t curr_sample_r; int32_t next_sample_r; int mix_right; } AV_HQMixerChannelInfo; #if CONFIG_HIGH_QUALITY_MIXER static const char *high_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_high_quality_mixer_class = { "AVSequencer High Quality Mixer", high_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_HQMixerChannelInfo *channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; - uint32_t i = len >> 2; - int32_t c1 = channel_block->filter_c1; - int32_t c2 = channel_block->filter_c2; - int32_t c3 = channel_block->filter_c3; - int32_t o1 = channel_info->filter_tmp2; - int32_t o2 = channel_info->filter_tmp1; + uint32_t i = len >> 2; + const int64_t c1 = channel_block->filter_c1; + const int64_t c2 = channel_block->filter_c2; + const int64_t c3 = channel_block->filter_c3; + int32_t o1 = channel_info->filter_tmp2; + int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { - mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; - mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; - mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; - mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; + mix_buf[0] += o3 = ((c1 * src_buf[0]) + (c2 * o2) + (c3 * o1)) >> 24; + mix_buf[1] += o4 = ((c1 * src_buf[1]) + (c2 * o3) + (c3 * o2)) >> 24; + mix_buf[2] += o1 = ((c1 * src_buf[2]) + (c2 * o4) + (c3 * o3)) >> 24; + mix_buf[3] += o2 = ((c1 * src_buf[3]) + (c2 * o1) + (c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { - *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; + *mix_buf++ += o3 = ((c1 * *src_buf++) + (c2 * o2) + (c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset_one_shoot += (offset > channel_info->current.offset) ? (offset - channel_info->current.offset) : (channel_info->current.offset - offset); if (channel_info->current.offset_one_shoot >= channel_info->current.len) { channel_info->current.offset_one_shoot = channel_info->current.len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index d46007a..b439978 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -1,658 +1,658 @@ /* * Sequencer low quality integer mixer * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer low quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_LQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_LQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_LQMixerData; typedef struct AV_LQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t offset_one_shoot; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint16_t filter_cutoff; uint16_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; } AV_LQMixerChannelInfo; #if CONFIG_LOW_QUALITY_MIXER static const char *low_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_low_quality_mixer_class = { "AVSequencer Low Quality Mixer", low_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_LQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; - uint32_t i = len >> 2; - int32_t c1 = channel_block->filter_c1; - int32_t c2 = channel_block->filter_c2; - int32_t c3 = channel_block->filter_c3; - int32_t o1 = channel_info->filter_tmp2; - int32_t o2 = channel_info->filter_tmp1; + uint32_t i = len >> 2; + const int64_t c1 = channel_block->filter_c1; + const int64_t c2 = channel_block->filter_c2; + const int64_t c3 = channel_block->filter_c3; + int32_t o1 = channel_info->filter_tmp2; + int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { - mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; - mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; - mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; - mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; + mix_buf[0] += o3 = ((c1 * src_buf[0]) + (c2 * o2) + (c3 * o1)) >> 24; + mix_buf[1] += o4 = ((c1 * src_buf[1]) + (c2 * o3) + (c3 * o2)) >> 24; + mix_buf[2] += o1 = ((c1 * src_buf[2]) + (c2 * o4) + (c3 * o3)) >> 24; + mix_buf[3] += o2 = ((c1 * src_buf[3]) + (c2 * o1) + (c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { - *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; + *mix_buf++ += o3 = ((c1 * *src_buf++) + (c2 * o2) + (c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset_one_shoot += (offset > channel_info->current.offset) ? (offset - channel_info->current.offset) : (channel_info->current.offset - offset); if (channel_info->current.offset_one_shoot >= channel_info->current.len) { channel_info->current.offset_one_shoot = channel_info->current.len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) = channel_info->current.mix_func; int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset;
BastyCDGS/ffmpeg-soc
132e4eae8c2b6a1ba2fcc29fa54c1e38c3c7fa85
Cleaned up nits in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 8c0de0b..916e735 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -3310,3551 +3310,2460 @@ static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); return divs_128(tmp_128, div_volume); } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_sample_1_x, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += ((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31; *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_sample_1_x, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); channel_info->mix_right = 0; *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; channel_info->mix_right = 1; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); channel_info->mix_right = 0; *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_sample_1_x, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_right) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_8, get_sample_1_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_8, get_backwards_sample_1_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_16_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_16_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_32_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_32_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_x_to_8, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_x_to_8, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_16, get_sample_1_16, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_16, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_16, get_backwards_sample_1_16, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_16, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_32, get_sample_1_32, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_32, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_32, get_backwards_sample_1_32, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_32, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_x, get_sample_1_x, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_x, get_sample_1_x, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_x, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); - mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_x, get_backwards_sample_1_x, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); + mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_backwards_next_sample_x, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); - mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_right_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_sample_1_x, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_center) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_center_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } static void mix_surround_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += ~smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_surround(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += ~smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_sample_1_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_8, get_backwards_sample_1_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_8; - channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_sample_1_16_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_16_to_8, get_backwards_sample_1_16_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16_to_8; - channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_sample_1_32_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_32_to_8, get_backwards_sample_1_32_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32_to_8; - channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_sample_1_x_to_8, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x_to_8, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x_to_8; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x_to_8; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_x_to_8, get_backwards_sample_1_x_to_8, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x_to_8; - channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x_to_8, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_16; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_sample_1_16, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_16, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_16; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_16; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_16, get_backwards_sample_1_16, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_16; - channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_16, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_32; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_sample_1_32, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_32, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_32; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_32; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_32, get_backwards_sample_1_32, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_32; - channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_32, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_sample_1_x; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_sample_1_x, 1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_x, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_surround) { if (advance) { - int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *const channel_block, - const uint32_t offset) = get_curr_sample_x; - int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, - const struct AV_HQMixerChannelInfo *const channel_info, - const struct ChannelBlock *channel_block, - uint32_t offset) = get_backwards_sample_1_x; - - mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_x, get_backwards_sample_1_x, -1, offset, fraction, advance, adv_frac, len); } else { - void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, - struct AV_HQMixerChannelInfo *const channel_info, - struct ChannelBlock *const channel_block, - uint32_t offset) = get_backwards_next_sample_x; - channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); - mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); + mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_backwards_next_sample_x, -1, offset, fraction, advance, adv_frac, len); } } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_HQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { const uint64_t left_volume = volume * (255 - panning); const uint64_t right_volume = volume * panning; channel_block->mult_left_volume = (left_volume * (uint64_t) mixer_data->amplify * (uint64_t) mixer_data->mixer_data.volume_left) >> 16; channel_block->mult_right_volume = (right_volume * (uint64_t) mixer_data->amplify * (uint64_t) mixer_data->mixer_data.volume_right) >> 16; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_16_left) { channel_block->mult_left_volume = (volume * (uint64_t) mixer_data->amplify * (uint64_t) mixer_data->mixer_data.volume_left) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_16_right) { channel_block->mult_right_volume = (volume * (uint64_t) mixer_data->amplify * (uint64_t) mixer_data->mixer_data.volume_right) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_16_center) { channel_block->mult_left_volume = (volume * (uint64_t) mixer_data->amplify * (uint64_t) mixer_data->mixer_data.volume_left) >> 9; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_16_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_16, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_16_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_16_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_16_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_16_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center, mix_stereo_x_to_8_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_to_8_center, mix_stereo_backwards_32_to_8_center, mix_stereo_backwards_x_to_8_center }; static const void *mixer_stereo_surround_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_surround, mix_stereo_16_to_8_surround, mix_stereo_32_to_8_surround, mix_stereo_x_to_8_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_to_8_surround, mix_stereo_backwards_32_to_8_surround, mix_stereo_backwards_x_to_8_surround }; static void set_mix_functions(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { void **mix_func; void (*init_mixer_func)(const AV_HQMixerData *const mixer_data, struct ChannelBlock *channel_block, uint32_t volume, uint32_t panning); uint32_t panning = 0x80; if ((channel_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip_16_to_8; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono_16_to_8; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround_16_to_8; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is 16777216*(2*PI*110*(2^0.25)*2^(x/768)). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 13801996550), INT64_C( 13814458963), INT64_C( 13826932630), INT64_C( 13839417559), INT64_C( 13851913761), INT64_C( 13864421247), INT64_C( 13876940026), INT64_C( 13889470109), INT64_C( 13902011506), INT64_C( 13914564228), INT64_C( 13927128283), INT64_C( 13939703683), INT64_C( 13952290438), INT64_C( 13964888559), INT64_C( 13977498054), INT64_C( 13990118935), INT64_C( 14002751212), INT64_C( 14015394896), INT64_C( 14028049996), INT64_C( 14040716522), INT64_C( 14053394486), INT64_C( 14066083898), INT64_C( 14078784767), INT64_C( 14091497104), INT64_C( 14104220920), INT64_C( 14116956225), INT64_C( 14129703029), INT64_C( 14142461342), INT64_C( 14155231176), INT64_C( 14168012540), INT64_C( 14180805445), INT64_C( 14193609901), INT64_C( 14206425919), INT64_C( 14219253509), INT64_C( 14232092681), INT64_C( 14244943447), INT64_C( 14257805816), INT64_C( 14270679799), INT64_C( 14283565407), INT64_C( 14296462649), INT64_C( 14309371537), INT64_C( 14322292081), INT64_C( 14335224292), INT64_C( 14348168179), INT64_C( 14361123755), INT64_C( 14374091028), INT64_C( 14387070010), INT64_C( 14400060711), INT64_C( 14413063142), INT64_C( 14426077314), INT64_C( 14439103236), INT64_C( 14452140921), INT64_C( 14465190377), INT64_C( 14478251617), INT64_C( 14491324650), INT64_C( 14504409487), INT64_C( 14517506139), INT64_C( 14530614617), INT64_C( 14543734931), INT64_C( 14556867091), INT64_C( 14570011110), INT64_C( 14583166996), INT64_C( 14596334762), INT64_C( 14609514417), INT64_C( 14622705973), INT64_C( 14635909440), INT64_C( 14649124829), INT64_C( 14662352151), INT64_C( 14675591416), INT64_C( 14688842636), INT64_C( 14702105820), INT64_C( 14715380981), INT64_C( 14728668128), INT64_C( 14741967273), INT64_C( 14755278426), INT64_C( 14768601599), INT64_C( 14781936801), INT64_C( 14795284045), INT64_C( 14808643340), INT64_C( 14822014698), INT64_C( 14835398129), INT64_C( 14848793645), INT64_C( 14862201256), INT64_C( 14875620974), INT64_C( 14889052809), INT64_C( 14902496772), INT64_C( 14915952874), INT64_C( 14929421126), INT64_C( 14942901539), INT64_C( 14956394125), INT64_C( 14969898893), INT64_C( 14983415856), INT64_C( 14996945023), INT64_C( 15010486407), INT64_C( 15024040017), INT64_C( 15037605866), INT64_C( 15051183964), INT64_C( 15064774322), INT64_C( 15078376952), INT64_C( 15091991863), INT64_C( 15105619069), INT64_C( 15119258579), INT64_C( 15132910404), INT64_C( 15146574557), INT64_C( 15160251047), INT64_C( 15173939887), INT64_C( 15187641087), INT64_C( 15201354658), INT64_C( 15215080611), INT64_C( 15228818959), INT64_C( 15242569711), INT64_C( 15256332880), INT64_C( 15270108476), INT64_C( 15283896510), INT64_C( 15297696995), INT64_C( 15311509940), INT64_C( 15325335358), INT64_C( 15339173259), INT64_C( 15353023655), INT64_C( 15366886557), INT64_C( 15380761977), INT64_C( 15394649925), INT64_C( 15408550413), INT64_C( 15422463453), INT64_C( 15436389055), INT64_C( 15450327231), INT64_C( 15464277993), INT64_C( 15478241352), INT64_C( 15492217318), INT64_C( 15506205904), INT64_C( 15520207121), INT64_C( 15534220980), INT64_C( 15548247493), INT64_C( 15562286671), INT64_C( 15576338526), INT64_C( 15590403069), INT64_C( 15604480311), INT64_C( 15618570264), INT64_C( 15632672940), INT64_C( 15646788349), INT64_C( 15660916504), INT64_C( 15675057416), INT64_C( 15689211096), INT64_C( 15703377556), INT64_C( 15717556808), INT64_C( 15731748863), INT64_C( 15745953732), INT64_C( 15760171428), INT64_C( 15774401961), INT64_C( 15788645344), INT64_C( 15802901587), INT64_C( 15817170703), INT64_C( 15831452704), INT64_C( 15845747600), INT64_C( 15860055404), INT64_C( 15874376126), INT64_C( 15888709780), INT64_C( 15903056376), INT64_C( 15917415926), INT64_C( 15931788442), INT64_C( 15946173936), INT64_C( 15960572419), INT64_C( 15974983903), INT64_C( 15989408400), INT64_C( 16003845921), INT64_C( 16018296478), INT64_C( 16032760084), INT64_C( 16047236749), INT64_C( 16061726486), INT64_C( 16076229306), INT64_C( 16090745222), INT64_C( 16105274244), INT64_C( 16119816386), INT64_C( 16134371658), INT64_C( 16148940072), INT64_C( 16163521642), INT64_C( 16178116377), INT64_C( 16192724291), INT64_C( 16207345394), INT64_C( 16221979700), INT64_C( 16236627220), INT64_C( 16251287966), INT64_C( 16265961949), INT64_C( 16280649182), INT64_C( 16295349677), INT64_C( 16310063446), INT64_C( 16324790500), INT64_C( 16339530852), INT64_C( 16354284514), INT64_C( 16369051497), INT64_C( 16383831815), INT64_C( 16398625478), INT64_C( 16413432498), INT64_C( 16428252889), INT64_C( 16443086662), INT64_C( 16457933828), INT64_C( 16472794401), INT64_C( 16487668392), INT64_C( 16502555814), INT64_C( 16517456678), INT64_C( 16532370996), INT64_C( 16547298782), INT64_C( 16562240046), INT64_C( 16577194801), INT64_C( 16592163060), INT64_C( 16607144834), INT64_C( 16622140136), INT64_C( 16637148978), INT64_C( 16652171372), INT64_C( 16667207330), INT64_C( 16682256865), INT64_C( 16697319988), INT64_C( 16712396713), INT64_C( 16727487051), INT64_C( 16742591015), INT64_C( 16757708617), INT64_C( 16772839870), INT64_C( 16787984785), INT64_C( 16803143375), INT64_C( 16818315652), INT64_C( 16833501629), INT64_C( 16848701318), INT64_C( 16863914732), INT64_C( 16879141882), INT64_C( 16894382782), INT64_C( 16909637443), INT64_C( 16924905878), INT64_C( 16940188100), INT64_C( 16955484121), INT64_C( 16970793953), INT64_C( 16986117609), INT64_C( 17001455102), INT64_C( 17016806443), INT64_C( 17032171646), INT64_C( 17047550723), INT64_C( 17062943686), INT64_C( 17078350548), INT64_C( 17093771322), INT64_C( 17109206020), INT64_C( 17124654654), INT64_C( 17140117238), INT64_C( 17155593783), INT64_C( 17171084303), INT64_C( 17186588810), INT64_C( 17202107316), INT64_C( 17217639835), INT64_C( 17233186379), INT64_C( 17248746961), INT64_C( 17264321593), INT64_C( 17279910288), INT64_C( 17295513058), INT64_C( 17311129917), INT64_C( 17326760877), INT64_C( 17342405951), INT64_C( 17358065152), INT64_C( 17373738492), INT64_C( 17389425984), INT64_C( 17405127641), INT64_C( 17420843475), INT64_C( 17436573501), INT64_C( 17452317729), INT64_C( 17468076174), INT64_C( 17483848847), INT64_C( 17499635763), INT64_C( 17515436933), INT64_C( 17531252370), INT64_C( 17547082089), INT64_C( 17562926100), INT64_C( 17578784418), INT64_C( 17594657054), INT64_C( 17610544023), INT64_C( 17626445337), INT64_C( 17642361009), INT64_C( 17658291052), INT64_C( 17674235479), INT64_C( 17690194302), INT64_C( 17706167536), INT64_C( 17722155192), INT64_C( 17738157285), INT64_C( 17754173826), INT64_C( 17770204830), INT64_C( 17786250308), INT64_C( 17802310275), INT64_C( 17818384743), INT64_C( 17834473725), INT64_C( 17850577234), INT64_C( 17866695285), INT64_C( 17882827888), INT64_C( 17898975059), INT64_C( 17915136810), INT64_C( 17931313153), INT64_C( 17947504104), INT64_C( 17963709673), INT64_C( 17979929875), INT64_C( 17996164724), INT64_C( 18012414231), INT64_C( 18028678411), INT64_C( 18044957276), INT64_C( 18061250840), INT64_C( 18077559117), INT64_C( 18093882118), INT64_C( 18110219859), INT64_C( 18126572352), INT64_C( 18142939610), INT64_C( 18159321646), INT64_C( 18175718475), INT64_C( 18192130109), INT64_C( 18208556562), INT64_C( 18224997847), INT64_C( 18241453978), INT64_C( 18257924967), INT64_C( 18274410829), INT64_C( 18290911577), INT64_C( 18307427224), INT64_C( 18323957783), INT64_C( 18340503269), INT64_C( 18357063694), INT64_C( 18373639073), INT64_C( 18390229418), INT64_C( 18406834743), INT64_C( 18423455062), INT64_C( 18440090388), INT64_C( 18456740735), INT64_C( 18473406116), INT64_C( 18490086545), INT64_C( 18506782035), INT64_C( 18523492601), INT64_C( 18540218255), INT64_C( 18556959012), INT64_C( 18573714884), INT64_C( 18590485886), INT64_C( 18607272032), INT64_C( 18624073334), INT64_C( 18640889807), INT64_C( 18657721464), INT64_C( 18674568319), INT64_C( 18691430386), INT64_C( 18708307679), INT64_C( 18725200211), INT64_C( 18742107995), INT64_C( 18759031047), INT64_C( 18775969379), INT64_C( 18792923005), INT64_C( 18809891940), INT64_C( 18826876196), INT64_C( 18843875788), INT64_C( 18860890730), INT64_C( 18877921036), INT64_C( 18894966719), INT64_C( 18912027793), INT64_C( 18929104272), INT64_C( 18946196171), INT64_C( 18963303502), INT64_C( 18980426280), INT64_C( 18997564519), INT64_C( 19014718234), INT64_C( 19031887436), INT64_C( 19049072142), INT64_C( 19066272365), INT64_C( 19083488118), INT64_C( 19100719416), INT64_C( 19117966273), INT64_C( 19135228703), INT64_C( 19152506720), INT64_C( 19169800338), INT64_C( 19187109571), INT64_C( 19204434434), INT64_C( 19221774940), INT64_C( 19239131103), INT64_C( 19256502938), INT64_C( 19273890458), INT64_C( 19291293679), INT64_C( 19308712614), INT64_C( 19326147277), INT64_C( 19343597682), INT64_C( 19361063844), INT64_C( 19378545778), INT64_C( 19396043496), INT64_C( 19413557014), INT64_C( 19431086345), INT64_C( 19448631505), INT64_C( 19466192507), INT64_C( 19483769365), INT64_C( 19501362094), INT64_C( 19518970709), INT64_C( 19536595223), INT64_C( 19554235651), INT64_C( 19571892007), INT64_C( 19589564306), INT64_C( 19607252562), INT64_C( 19624956789), INT64_C( 19642677003), INT64_C( 19660413217), INT64_C( 19678165445), INT64_C( 19695933703), INT64_C( 19713718004), INT64_C( 19731518364), INT64_C( 19749334797), INT64_C( 19767167316), INT64_C( 19785015938), INT64_C( 19802880675), INT64_C( 19820761544), INT64_C( 19838658558), INT64_C( 19856571732), INT64_C( 19874501080), INT64_C( 19892446618), INT64_C( 19910408359), INT64_C( 19928386319), INT64_C( 19946380512), INT64_C( 19964390952), INT64_C( 19982417656), INT64_C( 20000460636), INT64_C( 20018519908), INT64_C( 20036595486), INT64_C( 20054687386), INT64_C( 20072795621), INT64_C( 20090920207), INT64_C( 20109061159), INT64_C( 20127218491), INT64_C( 20145392218), INT64_C( 20163582355), INT64_C( 20181788916), INT64_C( 20200011917), INT64_C( 20218251373), INT64_C( 20236507297), INT64_C( 20254779706), INT64_C( 20273068613), INT64_C( 20291374035), INT64_C( 20309695985), INT64_C( 20328034478), INT64_C( 20346389531), INT64_C( 20364761157), INT64_C( 20383149371), INT64_C( 20401554189), INT64_C( 20419975625), INT64_C( 20438413695), INT64_C( 20456868414), INT64_C( 20475339796), INT64_C( 20493827856), INT64_C( 20512332611), INT64_C( 20530854074), INT64_C( 20549392261), INT64_C( 20567947186), INT64_C( 20586518866), INT64_C( 20605107315), INT64_C( 20623712548), INT64_C( 20642334581), INT64_C( 20660973429), INT64_C( 20679629106), INT64_C( 20698301628), INT64_C( 20716991010), INT64_C( 20735697268), INT64_C( 20754420417), INT64_C( 20773160471), INT64_C( 20791917447), INT64_C( 20810691359), INT64_C( 20829482223), INT64_C( 20848290054), INT64_C( 20867114867), INT64_C( 20885956678), INT64_C( 20904815502), INT64_C( 20923691355), INT64_C( 20942584252), INT64_C( 20961494207), INT64_C( 20980421237), INT64_C( 20999365358), INT64_C( 21018326583), INT64_C( 21037304930), INT64_C( 21056300413), INT64_C( 21075313048), INT64_C( 21094342850), INT64_C( 21113389835), INT64_C( 21132454018), INT64_C( 21151535416), INT64_C( 21170634042), INT64_C( 21189749914), INT64_C( 21208883046), INT64_C( 21228033454), INT64_C( 21247201154), INT64_C( 21266386161), INT64_C( 21285588491), INT64_C( 21304808160), INT64_C( 21324045183), INT64_C( 21343299576), INT64_C( 21362571355), INT64_C( 21381860535), INT64_C( 21401167132), INT64_C( 21420491162), INT64_C( 21439832640), INT64_C( 21459191583), INT64_C( 21478568005), INT64_C( 21497961923), INT64_C( 21517373353), INT64_C( 21536802311), INT64_C( 21556248811), INT64_C( 21575712871), INT64_C( 21595194505), INT64_C( 21614693731), INT64_C( 21634210563), INT64_C( 21653745017), INT64_C( 21673297111), INT64_C( 21692866858), INT64_C( 21712454276), INT64_C( 21732059380), INT64_C( 21751682187), INT64_C( 21771322712), INT64_C( 21790980971), INT64_C( 21810656980), INT64_C( 21830350756), INT64_C( 21850062314), INT64_C( 21869791670), INT64_C( 21889538841), INT64_C( 21909303843), INT64_C( 21929086691), INT64_C( 21948887402), INT64_C( 21968705991), INT64_C( 21988542476), INT64_C( 22008396872), INT64_C( 22028269196), INT64_C( 22048159463), INT64_C( 22068067690), INT64_C( 22087993893), INT64_C( 22107938088), INT64_C( 22127900291), INT64_C( 22147880519), INT64_C( 22167878788), INT64_C( 22187895115), INT64_C( 22207929515), INT64_C( 22227982005), INT64_C( 22248052601), INT64_C( 22268141320), INT64_C( 22288248178), INT64_C( 22308373191), INT64_C( 22328516376), INT64_C( 22348677749), INT64_C( 22368857327), INT64_C( 22389055126), INT64_C( 22409271162), INT64_C( 22429505452), INT64_C( 22449758012), INT64_C( 22470028860), INT64_C( 22490318010), INT64_C( 22510625481), INT64_C( 22530951288), INT64_C( 22551295448), INT64_C( 22571657978), INT64_C( 22592038894), INT64_C( 22612438213), INT64_C( 22632855951), INT64_C( 22653292126), INT64_C( 22673746753), INT64_C( 22694219849), INT64_C( 22714711431), INT64_C( 22735221517), INT64_C( 22755750121), INT64_C( 22776297262), INT64_C( 22796862955), INT64_C( 22817447219), INT64_C( 22838050068), INT64_C( 22858671521), INT64_C( 22879311594), INT64_C( 22899970304), INT64_C( 22920647667), INT64_C( 22941343701), INT64_C( 22962058422), INT64_C( 22982791847), INT64_C( 23003543993), INT64_C( 23024314878), INT64_C( 23045104517), INT64_C( 23065912928), INT64_C( 23086740128), INT64_C( 23107586134), INT64_C( 23128450963), INT64_C( 23149334631), INT64_C( 23170237156), INT64_C( 23191158555), INT64_C( 23212098844), INT64_C( 23233058042), INT64_C( 23254036164), INT64_C( 23275033229), INT64_C( 23296049252), INT64_C( 23317084252), INT64_C( 23338138246), INT64_C( 23359211249), INT64_C( 23380303281), INT64_C( 23401414358), INT64_C( 23422544496), INT64_C( 23443693714), INT64_C( 23464862028), INT64_C( 23486049457), INT64_C( 23507256016), INT64_C( 23528481723), INT64_C( 23549726597), INT64_C( 23570990653), INT64_C( 23592273909), INT64_C( 23613576383), INT64_C( 23634898091), INT64_C( 23656239053), INT64_C( 23677599283), INT64_C( 23698978801), INT64_C( 23720377623), INT64_C( 23741795767), INT64_C( 23763233251), INT64_C( 23784690091), INT64_C( 23806166306), INT64_C( 23827661912), INT64_C( 23849176928), INT64_C( 23870711371), INT64_C( 23892265258), INT64_C( 23913838606), INT64_C( 23935431435), INT64_C( 23957043760), INT64_C( 23978675600), INT64_C( 24000326973), INT64_C( 24021997895), INT64_C( 24043688385), INT64_C( 24065398461), INT64_C( 24087128139), INT64_C( 24108877438), INT64_C( 24130646375), INT64_C( 24152434968), INT64_C( 24174243236), INT64_C( 24196071194), INT64_C( 24217918863), INT64_C( 24239786258), INT64_C( 24261673399), INT64_C( 24283580302), INT64_C( 24305506986), INT64_C( 24327453468), INT64_C( 24349419767), INT64_C( 24371405901),
BastyCDGS/ffmpeg-soc
1c6596f5b0ab9eae18ff9615a032ab2eda462b67
Fixed sign comparision of high quality mixer backward looping calculation on average sample looping.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index da13f81..8c0de0b 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -2031,2122 +2031,2122 @@ static void get_backwards_next_sample_32(const AV_HQMixerData *const mixer_data, get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } muls_128(tmp_128, sample[offset - 1], mult_volume); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *const sample = (const int8_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int64_t tmp_128[2]; muls_128(tmp_128, sample[offset], mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - while (offset < end_offset) { + while ((int32_t) offset < (int32_t) end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); return divs_128(tmp_128, div_volume); } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance,
BastyCDGS/ffmpeg-soc
1f8f0598748e07d70649e87323b0f0a82d742dc9
Fixed one shoot counter in all AVSequencer mixers so it is updated upon different channel flags also.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index f5b7202..e26328c 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -7736,681 +7736,682 @@ static av_cold uint32_t set_tempo(AVMixerData *const mixer_data, hq_mixer_data->pass_len_frac = (((uint64_t) pass_value % hq_mixer_data->mixer_data.tempo) << 32) / hq_mixer_data->mixer_data.tempo; return tempo; } static av_cold uint32_t set_rate(AVMixerData *const mixer_data, const uint32_t mix_rate, const uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t buf_size, old_mix_rate, mix_rate_frac; hq_mixer_data->mixer_data.rate = mix_rate; buf_size = hq_mixer_data->mixer_data.mix_buf_size; hq_mixer_data->mixer_data.channels_out = channels; if ((hq_mixer_data->buf_size * hq_mixer_data->channels_out) != (buf_size * channels)) { int32_t *buf = hq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = hq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return hq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return hq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); hq_mixer_data->mixer_data.mix_buf = buf; hq_mixer_data->mixer_data.mix_buf_size = buf_size; hq_mixer_data->filter_buf = filter_buf; } hq_mixer_data->channels_out = channels; hq_mixer_data->buf = hq_mixer_data->mixer_data.mix_buf; hq_mixer_data->buf_size = hq_mixer_data->mixer_data.mix_buf_size; if (hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (hq_mixer_data->mix_rate != old_mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = old_mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; update_sample_filter(hq_mixer_data, channel_info, &channel_info->current); update_sample_filter(hq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { int32_t *volume_lut = hq_mixer_data->volume_lut; int64_t volume_mult = 0; int32_t volume_div = channels << 8; uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } - repeat = mixer_channel->repeat_start; - repeat_len = mixer_channel->repeat_length; - channel_info->current.repeat = repeat; - channel_info->current.repeat_len = repeat_len; + channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; + repeat = mixer_channel->repeat_start; + repeat_len = mixer_channel->repeat_length; + channel_info->current.repeat = repeat; + channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(hq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext high_quality_mixer = { .av_class = &avseq_high_quality_mixer_class, .name = "High quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for quality and supports advanced interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_HIGH_QUALITY_MIXER */ diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 77977b9..f198abe 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -5143,681 +5143,682 @@ static av_cold int uninit(AVMixerData *const mixer_data) } static av_cold uint32_t set_tempo(AVMixerData *const mixer_data, const uint32_t tempo) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; uint32_t channel_rate = lq_mixer_data->mix_rate * 10; uint64_t pass_value; lq_mixer_data->mixer_data.tempo = tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) lq_mixer_data->mix_rate_frac >> 16); lq_mixer_data->pass_len = (uint64_t) pass_value / lq_mixer_data->mixer_data.tempo; lq_mixer_data->pass_len_frac = (((uint64_t) pass_value % lq_mixer_data->mixer_data.tempo) << 32) / lq_mixer_data->mixer_data.tempo; return tempo; } static av_cold uint32_t set_rate(AVMixerData *const mixer_data, const uint32_t mix_rate, const uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; uint32_t buf_size, old_mix_rate, mix_rate_frac; lq_mixer_data->mixer_data.rate = mix_rate; buf_size = lq_mixer_data->mixer_data.mix_buf_size; lq_mixer_data->mixer_data.channels_out = channels; if ((lq_mixer_data->buf_size * lq_mixer_data->channels_out) != (buf_size * channels)) { int32_t *buf = lq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = lq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return lq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return lq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); lq_mixer_data->mixer_data.mix_buf = buf; lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != old_mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = old_mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; update_sample_filter(lq_mixer_data, channel_info, &channel_info->current); update_sample_filter(lq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = lq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { int32_t *volume_lut = lq_mixer_data->volume_lut; int64_t volume_mult = 0; int32_t volume_div = channels << 8; uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(lq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, 4095, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, 4095, 0); } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } - repeat = mixer_channel->repeat_start; - repeat_len = mixer_channel->repeat_length; - channel_info->current.repeat = repeat; - channel_info->current.repeat_len = repeat_len; + channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; + repeat = mixer_channel->repeat_start; + repeat_len = mixer_channel->repeat_length; + channel_info->current.repeat = repeat; + channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (const AV_LQMixerData *const) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(lq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_LOW_QUALITY_MIXER */ diff --git a/libavsequencer/null_mixer.c b/libavsequencer/null_mixer.c index 8c1cfc4..05813cb 100644 --- a/libavsequencer/null_mixer.c +++ b/libavsequencer/null_mixer.c @@ -564,673 +564,674 @@ static av_cold AVMixerData *init(AVMixerContext *const mixctx, for (i = null_mixer_data->channels_in; i > 0; i--) { channel_info->current.filter_cutoff = 4095; channel_info->next.filter_cutoff = 4095; channel_info++; } return (AVMixerData *) null_mixer_data; } static av_cold int uninit(AVMixerData *const mixer_data) { AV_NULLMixerData *null_mixer_data = (AV_NULLMixerData *) mixer_data; if (!null_mixer_data) return AVERROR_INVALIDDATA; av_freep(&null_mixer_data->channel_info); av_freep(&null_mixer_data->mixer_data.mix_buf); av_free(null_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *const mixer_data, const uint32_t tempo) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; const uint32_t channel_rate = null_mixer_data->mix_rate * 10; uint64_t pass_value; null_mixer_data->mixer_data.tempo = tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) null_mixer_data->mix_rate_frac >> 16); null_mixer_data->pass_len = (uint64_t) pass_value / null_mixer_data->mixer_data.tempo; null_mixer_data->pass_len_frac = (((uint64_t) pass_value % null_mixer_data->mixer_data.tempo) << 32) / null_mixer_data->mixer_data.tempo; return tempo; } static av_cold uint32_t set_rate(AVMixerData *const mixer_data, const uint32_t mix_rate, const uint32_t channels) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; uint32_t buf_size, old_mix_rate, mix_rate_frac; buf_size = null_mixer_data->mixer_data.mix_buf_size; null_mixer_data->mixer_data.rate = mix_rate; null_mixer_data->mixer_data.channels_out = channels; if ((null_mixer_data->mixer_data.mix_buf_size * null_mixer_data->channels_out) != (buf_size * channels)) { int32_t *buf = null_mixer_data->mixer_data.mix_buf; const uint32_t mix_buf_mem_size = (buf_size * channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(null_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output channel data.\n"); return null_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); null_mixer_data->mixer_data.mix_buf = buf; null_mixer_data->mixer_data.mix_buf_size = buf_size; } null_mixer_data->channels_out = channels; if (null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (null_mixer_data->mix_rate != old_mix_rate) { AV_NULLMixerChannelInfo *channel_info = null_mixer_data->channel_info; uint16_t i; null_mixer_data->mix_rate = old_mix_rate; null_mixer_data->mix_rate_frac = mix_rate_frac; if (null_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, null_mixer_data->mixer_data.tempo); for (i = null_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *channel_info = NULL; AV_NULLMixerChannelInfo *const old_channel_info = null_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = null_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_NULLMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(null_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } null_mixer_data->mixer_data.volume_boost = amplify; null_mixer_data->mixer_data.volume_left = left_volume; null_mixer_data->mixer_data.volume_right = right_volume; null_mixer_data->mixer_data.channels_in = channels; if (old_channels && channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_NULLMixerChannelInfo)); null_mixer_data->channel_info = channel_info; null_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { channel_info->current.filter_cutoff = 4095; channel_info->next.filter_cutoff = 4095; channel_info++; } av_free(old_channel_info); } channel_info = null_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(null_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; const AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel->pos_one_shoot; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_cutoff = 4095; channel_block->filter_damping = 0; channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->offset_one_shoot = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_cutoff = 4095; channel_block->filter_damping = 0; } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; const AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->pos_one_shoot = channel_info->current.offset_one_shoot; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->pos_one_shoot = channel_info->next.offset_one_shoot; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_current->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel_current->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel_current->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->offset_one_shoot = mixer_channel_next->pos_one_shoot; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; if ((channel_block->filter_cutoff = mixer_channel_next->filter_cutoff) > 4095) channel_block->filter_cutoff = 4095; if ((channel_block->filter_damping = mixer_channel_next->filter_damping) > 4095) channel_block->filter_damping = 4095; set_sample_mix_rate(null_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = null_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = null_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } - repeat = mixer_channel->repeat_start; - repeat_len = mixer_channel->repeat_length; - channel_info->current.repeat = repeat; - channel_info->current.repeat_len = repeat_len; + channel_info->current.offset_one_shoot = mixer_channel->pos_one_shoot; + repeat = mixer_channel->repeat_start; + repeat_len = mixer_channel->repeat_length; + channel_info->current.repeat = repeat; + channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_NULLMixerData *const null_mixer_data = (const AV_NULLMixerData *const) mixer_data; AV_NULLMixerChannelInfo *const channel_info = null_mixer_data->channel_info + channel; if ((channel_info->current.filter_cutoff = mixer_channel->filter_cutoff) > 4095) channel_info->current.filter_cutoff = 4095; if ((channel_info->current.filter_damping = mixer_channel->filter_damping) > 4095) channel_info->current.filter_damping = 4095; } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = null_mixer_data->mix_rate; current_left = null_mixer_data->current_left; current_left_frac = null_mixer_data->current_left_frac; buf_size = null_mixer_data->mixer_data.mix_buf_size; while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(null_mixer_data, mix_len); } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = null_mixer_data->pass_len; current_left_frac += null_mixer_data->pass_len_frac; if (current_left_frac < null_mixer_data->pass_len_frac) current_left++; } null_mixer_data->current_left = current_left; null_mixer_data->current_left_frac = current_left_frac; } } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_NULLMixerData *const null_mixer_data = (AV_NULLMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(null_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = null_mixer_data->mix_rate; current_left = null_mixer_data->current_left; current_left_frac = null_mixer_data->current_left_frac; buf_size = null_mixer_data->mixer_data.mix_buf_size; while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(null_mixer_data, mix_len, first_channel, last_channel); } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = null_mixer_data->pass_len; current_left_frac += null_mixer_data->pass_len_frac; if (current_left_frac < null_mixer_data->pass_len_frac) current_left++; } null_mixer_data->current_left = current_left; null_mixer_data->current_left_frac = current_left_frac; } } AVMixerContext null_mixer = { .av_class = &avseq_null_mixer_class, .name = "Null mixer", .description = NULL_IF_CONFIG_SMALL("Always outputs silence and simulates basic mixing"), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_NULL_MIXER */
BastyCDGS/ffmpeg-soc
99acabed62a4ebe343728f436033ee887058b62c
Fixed NNA same channel allocation in AVSequencer player when tremor was turning off note at that point.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 8e92af7..029e0bd 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -8818,1025 +8818,1025 @@ static const AVSequencerPlayerEffects fx_lut[128] = { {set_synth_value, NULL, NULL, 0x00, 0x01, 0x0000}, {envelope_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_envelope_value, NULL, NULL, 0x00, 0x01, 0x0000}, {nna_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {loop_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_speed, NULL, NULL, 0x00, 0x00, 0x0000}, {speed_slide_faster, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {speed_slide_slower, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_speed_slide_faster, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {fine_speed_slide_slower, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {speed_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {spenolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {spenolo, NULL, NULL, 0x00, 0x00, 0x0000}, {channel_ctrl, NULL, check_channel_control, 0x00, 0x00, 0x0000}, {set_global_volume, NULL, NULL, 0x00, 0x00, 0x0000}, {global_volume_slide_up, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_volume_slide_down, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_volume_slide_up, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {fine_global_volume_slide_down, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {global_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, 0x00, 0x00, 0x0000}, {set_global_panning, NULL, NULL, 0x00, 0x00, 0x0000}, {global_panning_slide_left, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_panning_slide_right, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_panning_slide_left, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {fine_global_panning_slide_right, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {global_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {global_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_pannolo, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {user_sync, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0000} }; static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerTrack *track; const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *track_data; uint32_t fx = -1; if (!(track = player_host_channel->track)) return; track_data = track->data + player_host_channel->row; if ((track_fx = player_host_channel->effect)) { while (++fx < track_data->effects) { if (track_fx == track_data->effects_data[fx]) break; } } else if (track_data->effects) { fx = 0; track_fx = track_data->effects_data[0]; } else { track_fx = NULL; } player_host_channel->effect = track_fx; if ((fx < track_data->effects) && track_data->effects_data[fx]) { do { const int fx_byte = track_fx->command & 0x7F; if (fx_byte == AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = track_fx->data; if (player_host_channel->tempo_counter < player_host_channel->exec_fx) break; } } while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))); if (player_host_channel->effect != track_fx) { player_host_channel->effect = track_fx; AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*pre_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); const int fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; if ((pre_fx_func = effects_lut->pre_pattern_func)) pre_fx_func(avctx, player_host_channel, player_channel, channel, track_fx->data); } } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= (player_host_channel->sample == player_channel->sample); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= (player_host_channel->sample == player_channel->sample); return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; - if (nna_volume || !player_channel->final_volume || !(nna = player_host_channel->nna)) + if (nna_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_channel->mixer.pos_one_shoot = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope *(**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope *(**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; player_channel->global_instr_volume = instrument->global_volume; player_channel->volume_swing = instrument->volume_swing; volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; player_channel->auto_pannolo_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; player_channel->auto_pannolo_depth = sample->pannolo_depth; player_channel->auto_pannolo_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->retrig_tick_count = 0; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; } player_channel->pitch_pan_separation = instrument->pitch_pan_separation; player_channel->pitch_pan_center = instrument->pitch_pan_center; player_channel->panning_swing = instrument->panning_swing; panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing;
BastyCDGS/ffmpeg-soc
92be11e81e2fbd0c3ead8654e4e869332c484fb8
Fixed segfault in high quality mixer occuring on full right panned mixing.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 0c1af7a..f5b7202 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -4086,1440 +4086,1452 @@ MIX(mono_backwards_32) struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += ((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31; *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; - channel_info->mix_right = 1; - get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); channel_info->mix_right = 0; *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; channel_info->mix_right = 1; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); channel_info->mix_right = 0; *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_right) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; + channel_info->mix_right = 1; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block,
BastyCDGS/ffmpeg-soc
7dfb86fa457acdf6bdc22b84a2f9d1d08cf2b289
Fixed some nits, track, as well as global pannolo and synth sound SETWAVP instruction in AVSequencer player for new S3M compatibility.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 1089b40..8e92af7 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -2632,2002 +2632,2002 @@ EXECUTE_EFFECT(fine_portamento_up_once) data_word = player_host_channel->fine_porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_up_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->fine_tone_porta; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = v4; player_host_channel->tone_porta_once = v8; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(fine_portamento_down_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_down_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->fine_tone_porta; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v3; player_host_channel->tone_porta_once = v5; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->fine_tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v0; player_host_channel->tone_porta_once = v1; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = data_word; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(note_slide) { uint16_t note_slide_value, note_slide_type; if (!(note_slide_value = (uint8_t) data_word)) note_slide_value = player_host_channel->note_slide; player_host_channel->note_slide = note_slide_value; if (!(note_slide_type = (data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; player_host_channel->note_slide_type = note_slide_type; if (!(note_slide_type & 0x10)) note_slide_value = -note_slide_value; note_slide_value += player_host_channel->final_note; player_host_channel->final_note = note_slide_value; if (player_channel->host_channel == channel) player_channel->frequency = get_tone_pitch(avctx, player_host_channel, player_channel, note_slide_value); } EXECUTE_EFFECT(vibrato) { uint16_t vibrato_rate; int16_t vibrato_depth; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; vibrato_depth = (int8_t) data_word; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, vibrato_depth << 2); } EXECUTE_EFFECT(fine_vibrato) { uint16_t vibrato_rate; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, (int8_t) data_word); } EXECUTE_EFFECT(do_key_off) { if (data_word <= player_host_channel->tempo_counter) play_key_off(player_channel); } EXECUTE_EFFECT(hold_delay) { // TODO: Implement hold delay effect } EXECUTE_EFFECT(note_fade) { if (data_word <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } EXECUTE_EFFECT(note_cut) { if ((data_word & 0xFFF) <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) { player_channel->volume = 0; player_channel->sub_volume = 0; if (data_word & 0xF000) { player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_channel->mixer.flags = 0; } } } } EXECUTE_EFFECT(note_delay) { } EXECUTE_EFFECT(tremor) { uint8_t tremor_off, tremor_on; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; if (!(tremor_off = (uint8_t) data_word)) tremor_off = player_host_channel->tremor_off_ticks; player_host_channel->tremor_off_ticks = tremor_off; if (!(tremor_on = (data_word >> 8))) tremor_on = player_host_channel->tremor_on_ticks; player_host_channel->tremor_on_ticks = tremor_on; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON)) tremor_off = tremor_on; if (player_host_channel->tremor_count-- <= 1) { player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON; player_host_channel->tremor_count = tremor_off; } } } EXECUTE_EFFECT(note_retrigger) { const AVSequencerSong *const song = avctx->player_song; uint16_t retrigger_tick = data_word & 0x7FFF, retrigger_tick_count = player_host_channel->retrig_tick_count; if (data_word & 0x8000) retrigger_tick = player_host_channel->tempo / (retrigger_tick ? retrigger_tick : 1); if ((song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_RETRIG_LOOP) && !retrigger_tick) return; if (retrigger_tick_count-- <= 1) { retrigger_tick_count = retrigger_tick; if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_RETRIG_LOOP)) player_channel->mixer.pos_one_shoot = 0; } } player_host_channel->retrig_tick_count = retrigger_tick_count; } EXECUTE_EFFECT(multi_retrigger_note) { const AVSequencerSong *const song = avctx->player_song; uint8_t multi_retrigger_tick, multi_retrigger_volume_change; uint16_t retrigger_tick_count; uint32_t volume; if (!(multi_retrigger_tick = (data_word >> 8))) multi_retrigger_tick = player_host_channel->multi_retrig_tick; player_host_channel->multi_retrig_tick = multi_retrigger_tick; if (!(multi_retrigger_volume_change = (uint8_t) data_word)) multi_retrigger_volume_change = player_host_channel->multi_retrig_vol_chg; player_host_channel->multi_retrig_vol_chg = multi_retrigger_volume_change; if ((song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_RETRIG_LOOP) && !multi_retrigger_tick) return; if (((retrigger_tick_count = player_host_channel->retrig_tick_count) > 1) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE) || (player_channel->host_channel != channel)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; } else if ((int8_t) multi_retrigger_volume_change < 0) { uint8_t multi_retrigger_scale = 4; - if (!(avctx->player_song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES)) + if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES)) multi_retrigger_scale = player_host_channel->multi_retrig_scale; if ((int8_t) (multi_retrigger_volume_change -= 0xBF) >= 0) { volume = multi_retrigger_volume_change * multi_retrigger_scale; if (player_channel->volume >= volume) { player_channel->volume -= volume; } else { player_channel->volume = 0; player_channel->sub_volume = 0; } } else { volume = ((multi_retrigger_volume_change + 0x40) * multi_retrigger_scale) + player_channel->volume; if (volume < 0x100) { player_channel->volume = volume; } else { player_channel->volume = 0xFF; player_channel->sub_volume = 0xFF; } } } else if ((int8_t) multi_retrigger_volume_change > 0) { uint8_t volume_multiplier, volume_divider; volume = player_channel->volume << 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) volume += player_channel->sub_volume; if ((volume_multiplier = (multi_retrigger_volume_change >> 4))) volume *= volume_multiplier; if ((volume_divider = (multi_retrigger_volume_change & 0xF))) volume /= volume_divider; if (volume > 0xFFFF) volume = 0xFFFF; player_channel->volume = volume >> 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) player_channel->sub_volume = volume; } if (retrigger_tick_count-- <= 1) { retrigger_tick_count = multi_retrigger_tick; if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_RETRIG_LOOP)) player_channel->mixer.pos_one_shoot = 0; } } player_host_channel->retrig_tick_count = retrigger_tick_count; } EXECUTE_EFFECT(extended_ctrl) { const AVSequencerModule *module; AVSequencerPlayerChannel *scan_player_channel; uint8_t extended_control_byte; uint16_t virtual_channel; const uint16_t extended_control_word = data_word & 0x0FFF; switch (data_word >> 12) { case 0 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; if (!extended_control_word) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; break; case 1 : player_host_channel->glissando = extended_control_word; break; case 2 : extended_control_byte = extended_control_word; switch (extended_control_word >> 8) { case 0 : if (!extended_control_byte) extended_control_byte = 1; if (extended_control_byte > 4) extended_control_byte = 4; player_host_channel->multi_retrig_scale = extended_control_byte; break; case 1 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; if (extended_control_byte) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; break; case 2 : if (extended_control_byte) player_host_channel->multi_retrig_tick = player_host_channel->tempo / extended_control_byte; break; } break; case 3 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->mixer.flags = 0; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 4 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 5 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) play_key_off(scan_player_channel); scan_player_channel++; } while (++virtual_channel < module->channels); break; case 6 : player_host_channel->sub_slide = extended_control_word; break; } } EXECUTE_EFFECT(invert_loop) { // TODO: Implement invert loop } EXECUTE_EFFECT(exec_fx) { } EXECUTE_EFFECT(stop_fx) { uint8_t stop_fx = data_word; if ((int8_t) stop_fx < 0) stop_fx = 127; if (!(data_word >>= 8)) data_word = player_host_channel->exec_fx; if (data_word >= player_host_channel->tempo_counter) player_host_channel->effects_used[(stop_fx >> 3)] |= (1 << (7 - (stop_fx & 7))); } EXECUTE_EFFECT(set_volume) { player_host_channel->tremolo_slide = 0; if (check_old_volume(avctx, player_channel, &data_word, channel)) { player_channel->volume = data_word >> 8; player_channel->sub_volume = data_word; } } EXECUTE_EFFECT(volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_ok(player_host_channel, data_word); volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_ok(player_host_channel, data_word); volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->fine_vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_once_ok(player_host_channel, data_word); fine_volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_once_ok(player_host_channel, data_word); fine_volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_to) { uint8_t volume_slide_to_value, volume_slide_to_volume; if (!(volume_slide_to_value = (uint8_t) data_word)) volume_slide_to_value = player_host_channel->volume_slide_to; player_host_channel->volume_slide_to = volume_slide_to_value; player_host_channel->volume_slide_to_slide &= 0x00FF; player_host_channel->volume_slide_to_slide += volume_slide_to_value << 8; volume_slide_to_volume = data_word >> 8; if (volume_slide_to_volume && (volume_slide_to_volume < 0xFF)) { player_host_channel->volume_slide_to_volume = volume_slide_to_volume; } else if (volume_slide_to_volume && (player_channel->host_channel == channel)) { const uint16_t volume_slide_target = (volume_slide_to_volume << 8) + player_host_channel->volume_slide_to_volume; uint16_t volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume < volume_slide_target) { do_volume_slide(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target <= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } else { do_volume_slide_down(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target >= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } } } EXECUTE_EFFECT(tremolo) { const AVSequencerSong *const song = avctx->player_song; int16_t tremolo_slide_value; uint8_t tremolo_rate; int16_t tremolo_depth; if (!(tremolo_rate = (data_word >> 8))) tremolo_rate = player_host_channel->tremolo_rate; player_host_channel->tremolo_rate = tremolo_rate; if (!(tremolo_depth = (int8_t) data_word)) tremolo_depth = player_host_channel->tremolo_depth; player_host_channel->tremolo_depth = tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (tremolo_depth > 63) tremolo_depth = 63; if (tremolo_depth < -63) tremolo_depth = -63; } tremolo_slide_value = (-(int32_t) tremolo_depth * run_envelope(avctx, &player_host_channel->tremolo_env, tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) tremolo_slide_value <<= 2; if (player_channel->host_channel == channel) { const uint16_t volume = player_channel->volume; tremolo_slide_value -= player_host_channel->tremolo_slide; if ((int16_t) (tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_host_channel->tremolo_slide -= volume - tremolo_slide_value; } } EXECUTE_EFFECT(set_track_volume) { if (check_old_track_volume(avctx, &data_word)) { player_host_channel->track_volume = data_word >> 8; player_host_channel->track_sub_volume = data_word; } } EXECUTE_EFFECT(track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_host_channel->track_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_up; v5 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_vol_slide_up = data_word; player_host_channel->track_vol_slide_down = v3; player_host_channel->fine_trk_vol_slide_up = v4; player_host_channel->fine_trk_vol_slide_dn = v5; } EXECUTE_EFFECT(track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_host_channel->track_vol_slide_down; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v3 = player_host_channel->fine_trk_vol_slide_up; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = data_word; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = data_word; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_dn; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v3 = player_host_channel->fine_trk_vol_slide_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = data_word; } EXECUTE_EFFECT(track_volume_slide_to) { uint8_t track_vol_slide_to, track_volume_slide_to_volume; if (!(track_vol_slide_to = (uint8_t) data_word)) track_vol_slide_to = player_host_channel->track_vol_slide_to; player_host_channel->track_vol_slide_to = track_vol_slide_to; player_host_channel->track_vol_slide_to_slide &= 0x00FF; player_host_channel->track_vol_slide_to_slide += track_vol_slide_to << 8; track_volume_slide_to_volume = data_word >> 8; if (track_volume_slide_to_volume && (track_volume_slide_to_volume < 0xFF)) { player_host_channel->track_vol_slide_to = track_volume_slide_to_volume; } else if (track_volume_slide_to_volume) { const uint16_t track_volume_slide_target = (track_volume_slide_to_volume << 8) + player_host_channel->track_vol_slide_to_sub_volume; uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume < track_volume_slide_target) { do_track_volume_slide(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target <= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } else { do_track_volume_slide_down(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target >= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } } } EXECUTE_EFFECT(track_tremolo) { const AVSequencerSong *const song = avctx->player_song; int16_t track_tremolo_slide_value; uint8_t track_tremolo_rate; int16_t track_tremolo_depth; uint16_t track_volume; if (!(track_tremolo_rate = (data_word >> 8))) track_tremolo_rate = player_host_channel->track_trem_rate; player_host_channel->track_trem_rate = track_tremolo_rate; if (!(track_tremolo_depth = (int8_t) data_word)) track_tremolo_depth = player_host_channel->track_trem_depth; player_host_channel->track_trem_depth = track_tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (track_tremolo_depth > 63) track_tremolo_depth = 63; if (track_tremolo_depth < -63) track_tremolo_depth = -63; } track_tremolo_slide_value = (-(int32_t) track_tremolo_depth * run_envelope(avctx, &player_host_channel->track_trem_env, track_tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) track_tremolo_slide_value <<= 2; track_volume = player_host_channel->track_volume; track_tremolo_slide_value -= player_host_channel->track_trem_slide; if ((int16_t) (track_tremolo_slide_value += track_volume) < 0) track_tremolo_slide_value = 0; if (track_tremolo_slide_value > 255) track_tremolo_slide_value = 255; player_host_channel->track_volume = track_tremolo_slide_value; player_host_channel->track_trem_slide -= track_volume - track_tremolo_slide_value; } EXECUTE_EFFECT(set_panning) { const uint8_t panning = data_word >> 8; if (player_channel->host_channel == channel) { player_channel->panning = panning; player_channel->sub_panning = data_word; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = data_word; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = data_word; } EXECUTE_EFFECT(panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->pan_slide_left; do_panning_slide(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v3 = player_host_channel->pan_slide_right; v4 = player_host_channel->fine_pan_slide_left; v5 = player_host_channel->fine_pan_slide_right; v8 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->pan_slide_left = data_word; player_host_channel->pan_slide_right = v3; player_host_channel->fine_pan_slide_left = v4; player_host_channel->fine_pan_slide_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->pan_slide_right; do_panning_slide_right(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v3 = player_host_channel->fine_pan_slide_left; v4 = player_host_channel->fine_pan_slide_right; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = data_word; player_host_channel->fine_pan_slide_left = v3; player_host_channel->fine_pan_slide_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_pan_slide_left; do_panning_slide(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v1 = player_host_channel->pan_slide_right; v4 = player_host_channel->fine_pan_slide_right; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = v1; player_host_channel->fine_pan_slide_left = data_word; player_host_channel->fine_pan_slide_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_pan_slide_right; do_panning_slide_right(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v1 = player_host_channel->pan_slide_right; v3 = player_host_channel->fine_pan_slide_left; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = v1; player_host_channel->fine_pan_slide_left = v3; player_host_channel->fine_pan_slide_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(panning_slide_to) { uint8_t panning_slide_to_value, panning_slide_to_panning; if (!(panning_slide_to_value = (uint8_t) data_word)) panning_slide_to_value = player_host_channel->panning_slide_to; player_host_channel->panning_slide_to = panning_slide_to_value; player_host_channel->panning_slide_to_slide &= 0x00FF; player_host_channel->panning_slide_to_slide += panning_slide_to_value << 8; panning_slide_to_panning = data_word >> 8; if (panning_slide_to_panning && (panning_slide_to_panning < 0xFF)) { player_host_channel->panning_slide_to_panning = panning_slide_to_panning; } else if (panning_slide_to_panning && (player_channel->host_channel == channel)) { const uint16_t panning_slide_target = ((uint8_t) panning_slide_to_panning << 8) + player_host_channel->panning_slide_to_sub_panning; uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < panning_slide_target) { do_panning_slide_right(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target <= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } else { do_panning_slide(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target >= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } } } EXECUTE_EFFECT(pannolo) { int16_t pannolo_slide_value; uint8_t pannolo_rate; int16_t pannolo_depth; if (!(pannolo_rate = (data_word >> 8))) pannolo_rate = player_host_channel->pannolo_rate; player_host_channel->pannolo_rate = pannolo_rate; if (!(pannolo_depth = (int8_t) data_word)) pannolo_depth = player_host_channel->pannolo_depth; player_host_channel->pannolo_depth = pannolo_depth; pannolo_slide_value = (-(int32_t) pannolo_depth * run_envelope(avctx, &player_host_channel->pannolo_env, pannolo_rate, 0)) >> 7; if (player_channel->host_channel == channel) { const int16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_host_channel->pannolo_slide; if ((int16_t) (pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_host_channel->pannolo_slide -= panning - pannolo_slide_value; player_host_channel->track_note_panning = player_host_channel->track_panning = panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_channel->sub_panning; } } EXECUTE_EFFECT(set_track_panning) { player_host_channel->channel_panning = data_word >> 8; player_host_channel->channel_sub_panning = data_word; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; } EXECUTE_EFFECT(track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->track_pan_slide_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->fine_trk_pan_sld_right; v8 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_pan_slide_left = data_word; player_host_channel->track_pan_slide_right = v3; player_host_channel->fine_trk_pan_sld_left = v4; player_host_channel->fine_trk_pan_sld_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->track_pan_slide_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v3 = player_host_channel->fine_trk_pan_sld_left; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = data_word; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = data_word; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v3 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(track_panning_slide_to) { uint8_t track_pan_slide_to, track_panning_slide_to_panning; if (!(track_pan_slide_to = (uint8_t) data_word)) track_pan_slide_to = player_host_channel->track_pan_slide_to; player_host_channel->track_pan_slide_to = track_pan_slide_to; player_host_channel->track_pan_slide_to_slide &= 0x00FF; player_host_channel->track_pan_slide_to_slide += track_pan_slide_to << 8; track_panning_slide_to_panning = data_word >> 8; if (track_panning_slide_to_panning && (track_panning_slide_to_panning < 0xFF)) { player_host_channel->track_pan_slide_to_panning = track_panning_slide_to_panning; } else if (track_panning_slide_to_panning) { const uint16_t track_panning_slide_to_target = ((uint8_t) track_panning_slide_to_panning << 8) + player_host_channel->track_pan_slide_to_sub_panning; uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning < track_panning_slide_to_target) { do_track_panning_slide_right(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target <= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } else { do_track_panning_slide(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target >= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } } } EXECUTE_EFFECT(track_pannolo) { int16_t track_pannolo_slide_value; uint8_t track_pannolo_rate; int16_t track_pannolo_depth; - uint16_t track_panning; + int16_t track_panning; if (!(track_pannolo_rate = (data_word >> 8))) track_pannolo_rate = player_host_channel->track_pan_rate; player_host_channel->track_pan_rate = track_pannolo_rate; if (!(track_pannolo_depth = (int8_t) data_word)) track_pannolo_depth = player_host_channel->track_pan_depth; player_host_channel->track_pan_depth = track_pannolo_depth; track_pannolo_slide_value = (-(int32_t) track_pannolo_depth * run_envelope(avctx, &player_host_channel->track_pan_env, track_pannolo_rate, 0)) >> 7; track_panning = (uint8_t) player_host_channel->track_panning; track_pannolo_slide_value -= player_host_channel->track_pan_slide; if ((int16_t) (track_pannolo_slide_value += track_panning) < 0) track_pannolo_slide_value = 0; if (track_pannolo_slide_value > 255) track_pannolo_slide_value = 255; player_host_channel->track_panning = track_pannolo_slide_value; player_host_channel->track_pan_slide -= track_panning - track_pannolo_slide_value; } EXECUTE_EFFECT(set_tempo) { if (!(player_host_channel->tempo = data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(set_relative_tempo) { if (!(player_host_channel->tempo += data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(pattern_break) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = data_word; } } EXECUTE_EFFECT(position_jump) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { AVSequencerOrderData *order_data = NULL; if (data_word--) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; if ((data_word < order_list->orders) && order_list->order_data[data_word]) order_data = order_list->order_data[data_word]; } player_host_channel->order = order_data; pattern_break(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_PATT_BREAK, 0); } } EXECUTE_EFFECT(relative_position_jump) { if (!data_word) data_word = player_host_channel->pos_jump; if ((player_host_channel->pos_jump = data_word)) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; AVSequencerOrderData *order_data = player_host_channel->order; uint32_t ord = -1; while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; ord++; } ord += (int32_t) data_word; if (ord > 0xFFFF) ord = 0; position_jump(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_POS_JUMP, (uint16_t) ord); } } EXECUTE_EFFECT(change_pattern) { player_host_channel->chg_pattern = data_word; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; } EXECUTE_EFFECT(reverse_pattern_play) { if (!data_word) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else if (data_word & 0x8000) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; } EXECUTE_EFFECT(pattern_delay) { player_host_channel->pattern_delay = data_word; } EXECUTE_EFFECT(fine_pattern_delay) { player_host_channel->fine_pattern_delay = data_word; } EXECUTE_EFFECT(pattern_loop) { const AVSequencerSong *const song = avctx->player_song; uint16_t *loop_stack_ptr; uint16_t loop_length = player_host_channel->pattern_loop_depth; loop_stack_ptr = (uint16_t *) avctx->player_globals->loop_stack + (((song->loop_stack_size * channel) * sizeof (uint16_t[2])) + (loop_length * sizeof(uint16_t[2]))); if (data_word) { if (data_word == *loop_stack_ptr) { *loop_stack_ptr = 0; if (loop_length--) player_host_channel->pattern_loop_depth = loop_length; else player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; } else { (*loop_stack_ptr++)++; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; player_host_channel->break_row = *loop_stack_ptr; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } } else if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; *loop_stack_ptr++ = 0; *loop_stack_ptr = player_host_channel->row; if (++loop_length != song->loop_stack_size) player_host_channel->pattern_loop_depth = loop_length; } } EXECUTE_EFFECT(gosub) { // TODO: Implement GoSub effect } EXECUTE_EFFECT(gosub_return) { // TODO: Implement return effect } EXECUTE_EFFECT(channel_sync) { // TODO: Implement channel synchronizattion effect } EXECUTE_EFFECT(set_sub_slides) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t sub_slide_flags; if (!(sub_slide_flags = (data_word >> 8))) sub_slide_flags = player_host_channel->sub_slide_bits; if (sub_slide_flags & 0x01) player_host_channel->volume_slide_to_volume = data_word; if (sub_slide_flags & 0x02) player_host_channel->track_vol_slide_to_sub_volume = data_word; if (sub_slide_flags & 0x04) player_globals->global_volume_sl_to_sub_volume = data_word; if (sub_slide_flags & 0x08) player_host_channel->panning_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x10) player_host_channel->track_pan_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x20) player_globals->global_pan_slide_to_sub_panning = data_word; } EXECUTE_EFFECT(sample_offset_high) { player_host_channel->smp_offset_hi = data_word; } EXECUTE_EFFECT(sample_offset_low) { if (player_channel->host_channel == channel) { uint32_t sample_offset = (player_host_channel->smp_offset_hi << 16) + data_word; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL)) { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SAMPLE_OFFSET) { const AVSequencerSample *const sample = player_channel->sample; if (sample_offset >= sample->samples) return; } player_channel->mixer.pos = 0; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t repeat_end = player_channel->mixer.repeat_start + player_channel->mixer.repeat_length; if (repeat_end < sample_offset) sample_offset = repeat_end; } } player_channel->mixer.pos += sample_offset; player_channel->mixer.pos_one_shoot = player_channel->mixer.pos; } } EXECUTE_EFFECT(set_hold) { // TODO: Implement set hold effect } EXECUTE_EFFECT(set_decay) { // TODO: Implement set decay effect } EXECUTE_EFFECT(set_transpose) { // TODO: Implement set transpose effect } EXECUTE_EFFECT(instrument_ctrl) { const uint32_t flags = player_host_channel->flags; uint8_t off_bits = data_word >> 8; uint8_t on_bits = data_word; uint8_t xor_bits = off_bits & on_bits; if (xor_bits & 0x01) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; else if (off_bits & 0x01) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; else if (on_bits & 0x01) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (flags != player_host_channel->flags) { const AVSequencerInstrument *instrument; const AVSequencerSample *const sample = player_host_channel->sample; if (sample) { uint32_t panning, seed; panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if ((instrument = player_channel->instrument)) { uint32_t panning_swing; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } } } } if (xor_bits & 0x02) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; else if (off_bits & 0x02) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; else if (on_bits & 0x02) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (xor_bits & 0x08) player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; else if (off_bits & 0x08) player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; else if (on_bits & 0x08) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (xor_bits & 0x10) player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; else if (off_bits & 0x10) player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; else if (on_bits & 0x10) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; if (xor_bits & 0x20) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; else if (off_bits & 0x20) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; else if (on_bits & 0x20) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; if (xor_bits & 0x80) player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; else if (off_bits & 0x80) player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; else if (on_bits & 0x80) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; } EXECUTE_EFFECT(instrument_change) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample; AVMixerData *mixer; uint32_t volume, volume_swing, panning, abs_volume_swing, seed; switch (data_word >> 12) { case 0x0 : sample = player_host_channel->sample; volume = player_channel->instr_volume; player_channel->global_instr_volume = data_word; if (sample && (instrument = player_host_channel->instrument)) { volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else if (sample) { volume = player_channel->global_instr_volume * 255; } player_channel->instr_volume = volume; break; case 0x1 : sample = player_host_channel->sample; volume = player_channel->instr_volume; volume_swing = data_word & 0xFFF; if (sample && (instrument = player_host_channel->instrument)) { volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else if (sample) { volume = sample->global_volume * 255; volume_swing = (volume * instrument->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } player_channel->instr_volume = volume; player_channel->volume_swing = volume_swing; break; case 0x2 : if ((sample = player_host_channel->sample)) { panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if ((instrument = player_channel->instrument)) { uint32_t panning_swing; int32_t panning_separation; player_channel->panning_swing = panning_swing = data_word & 0xFFF; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; @@ -5443,1025 +5443,1025 @@ EXECUTE_EFFECT(speed_slide_to) EXECUTE_EFFECT(spenolo) { // TODO: Implement spenolo effect } EXECUTE_EFFECT(channel_ctrl) { const uint8_t channel_ctrl_byte = data_word; switch (data_word >> 8) { case 0x00 : break; case 0x01 : break; case 0x02 : break; case 0x03 : break; case 0x04 : break; case 0x05 : break; case 0x06 : break; case 0x07 : break; case 0x08 : break; case 0x09 : break; case 0x0A : break; case 0x10 : switch (channel_ctrl_byte) { case 0x00 : if (check_surround_track_panning(player_host_channel, player_channel, channel, 0)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } break; case 0x01 : if (check_surround_track_panning(player_host_channel, player_channel, channel, 1)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } break; case 0x10 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; break; case 0x11 : player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; break; case 0x20 : avctx->player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; break; case 0x21 : avctx->player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; break; } break; case 0x11 : break; } } EXECUTE_EFFECT(set_global_volume) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; if (check_old_track_volume(avctx, &data_word)) { player_globals->global_volume = data_word >> 8; player_globals->global_sub_volume = data_word; } } EXECUTE_EFFECT(global_volume_slide_up) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_globals->global_vol_slide_up; do_global_volume_slide(avctx, player_globals, data_word); track = player_host_channel->track; v3 = player_globals->global_vol_slide_down; v4 = player_globals->fine_global_vol_sl_up; v5 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->global_vol_slide_up = data_word; player_globals->global_vol_slide_down = v3; player_globals->fine_global_vol_sl_up = v4; player_globals->fine_global_vol_sl_down = v5; } EXECUTE_EFFECT(global_volume_slide_down) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_globals->global_vol_slide_down; do_global_volume_slide_down(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v3 = player_globals->fine_global_vol_sl_up; v4 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = data_word; player_globals->fine_global_vol_sl_up = v3; player_globals->fine_global_vol_sl_down = v4; } EXECUTE_EFFECT(fine_global_volume_slide_up) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_globals->fine_global_vol_sl_up; do_global_volume_slide(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v1 = player_globals->global_vol_slide_down; v4 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) data_word = v0; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = v1; player_globals->fine_global_vol_sl_up = data_word; player_globals->fine_global_vol_sl_down = v4; } EXECUTE_EFFECT(fine_global_volume_slide_down) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_globals->global_vol_slide_down; do_global_volume_slide_down(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v1 = player_globals->global_vol_slide_down; v3 = player_globals->fine_global_vol_sl_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = v1; player_globals->fine_global_vol_sl_up = v3; player_globals->fine_global_vol_sl_down = data_word; } EXECUTE_EFFECT(global_volume_slide_to) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t global_volume_slide_to_value, global_volume_slide_to_volume; if (!(global_volume_slide_to_value = (uint8_t) data_word)) global_volume_slide_to_value = player_globals->global_volume_slide_to; player_globals->global_volume_slide_to = global_volume_slide_to_value; player_globals->global_volume_slide_to_slide &= 0x00FF; player_globals->global_volume_slide_to_slide += global_volume_slide_to_value << 8; global_volume_slide_to_volume = data_word >> 8; if (global_volume_slide_to_volume && (global_volume_slide_to_volume < 0xFF)) { player_globals->global_volume_sl_to_volume = global_volume_slide_to_volume; } else if (global_volume_slide_to_volume) { const uint16_t global_volume_slide_target = (global_volume_slide_to_volume << 8) + player_globals->global_volume_sl_to_sub_volume; uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume < global_volume_slide_target) { do_global_volume_slide(avctx, player_globals, player_globals->global_volume_slide_to_slide); global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume_slide_target <= global_volume) { player_globals->global_volume = global_volume_slide_target >> 8; player_globals->global_sub_volume = global_volume_slide_target; } } else { do_global_volume_slide_down(avctx, player_globals, player_globals->global_volume_slide_to_slide); global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume_slide_target >= global_volume) { player_globals->global_volume = global_volume_slide_target >> 8; player_globals->global_sub_volume = global_volume_slide_target; } } } } EXECUTE_EFFECT(global_tremolo) { const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; int16_t global_tremolo_slide_value; uint8_t global_tremolo_rate; int16_t global_tremolo_depth; uint16_t global_volume; if (!(global_tremolo_rate = (data_word >> 8))) global_tremolo_rate = player_globals->tremolo_rate; player_globals->tremolo_rate = global_tremolo_rate; if (!(global_tremolo_depth = (int8_t) data_word)) global_tremolo_depth = (int8_t) player_globals->tremolo_depth; player_globals->tremolo_depth = global_tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (global_tremolo_depth > 63) global_tremolo_depth = 63; if (global_tremolo_depth < -63) global_tremolo_depth = -63; } global_tremolo_slide_value = (-(int32_t) global_tremolo_depth * run_envelope(avctx, &player_globals->tremolo_env, global_tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) global_tremolo_slide_value <<= 2; global_volume = player_globals->global_volume; global_tremolo_slide_value -= player_globals->tremolo_slide; if ((int16_t) (global_tremolo_slide_value += global_volume) < 0) global_tremolo_slide_value = 0; if (global_tremolo_slide_value > 255) global_tremolo_slide_value = 255; player_globals->global_volume = global_tremolo_slide_value; player_globals->tremolo_slide -= global_volume - global_tremolo_slide_value; } EXECUTE_EFFECT(set_global_panning) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; player_globals->global_panning = data_word >> 8; player_globals->global_sub_panning = data_word; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; } EXECUTE_EFFECT(global_panning_slide_left) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_globals->global_pan_slide_left; do_global_panning_slide(player_globals, data_word); track = player_host_channel->track; v3 = player_globals->global_pan_slide_right; v4 = player_globals->fine_global_pan_sl_left; v5 = player_globals->fine_global_pan_sl_right; v8 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->global_pan_slide_left = data_word; player_globals->global_pan_slide_right = v3; player_globals->fine_global_pan_sl_left = v4; player_globals->fine_global_pan_sl_right = v5; player_globals->global_pan_slide_to_slide = v8; } EXECUTE_EFFECT(global_panning_slide_right) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_globals->global_pan_slide_right; do_global_panning_slide_right(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v3 = player_globals->fine_global_pan_sl_left; v4 = player_globals->fine_global_pan_sl_right; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = data_word; player_globals->fine_global_pan_sl_left = v3; player_globals->fine_global_pan_sl_right = v4; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(fine_global_panning_slide_left) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_globals->fine_global_pan_sl_left; do_global_panning_slide(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v1 = player_globals->global_pan_slide_right; v4 = player_globals->fine_global_pan_sl_right; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = v1; player_globals->fine_global_pan_sl_left = data_word; player_globals->fine_global_pan_sl_right = v4; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(fine_global_panning_slide_right) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_globals->fine_global_pan_sl_right; do_global_panning_slide_right(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v1 = player_globals->global_pan_slide_right; v3 = player_globals->fine_global_pan_sl_left; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = v1; player_globals->fine_global_pan_sl_left = v3; player_globals->fine_global_pan_sl_right = data_word; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(global_panning_slide_to) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t global_pan_slide_to, global_pan_slide_to_panning; if (!(global_pan_slide_to = (uint8_t) data_word)) global_pan_slide_to = player_globals->global_pan_slide_to; player_globals->global_pan_slide_to = global_pan_slide_to; player_globals->global_pan_slide_to_slide &= 0x00FF; player_globals->global_pan_slide_to_slide += global_pan_slide_to << 8; global_pan_slide_to_panning = data_word >> 8; if (global_pan_slide_to_panning && (global_pan_slide_to_panning < 0xFF)) { player_globals->global_pan_slide_to_panning = global_pan_slide_to_panning; } else if (global_pan_slide_to_panning) { const uint16_t global_panning_slide_target = ((uint8_t) global_pan_slide_to_panning << 8) + player_globals->global_pan_slide_to_sub_panning; uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning < global_panning_slide_target) { do_global_panning_slide_right(player_globals, player_globals->global_pan_slide_to_slide); global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning_slide_target <= global_panning) { player_globals->global_panning = global_panning_slide_target >> 8; player_globals->global_sub_panning = global_panning_slide_target; } } else { do_global_panning_slide(player_globals, player_globals->global_pan_slide_to_slide); global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning_slide_target >= global_panning) { player_globals->global_panning = global_panning_slide_target >> 8; player_globals->global_sub_panning = global_panning_slide_target; } } } } EXECUTE_EFFECT(global_pannolo) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; int16_t global_pannolo_slide_value; uint8_t global_pannolo_rate; int16_t global_pannolo_depth; - uint16_t global_panning; + int16_t global_panning; if (!(global_pannolo_rate = (data_word >> 8))) global_pannolo_rate = player_globals->pannolo_rate; player_globals->pannolo_rate = global_pannolo_rate; if (!(global_pannolo_depth = (int8_t) data_word)) global_pannolo_depth = player_globals->pannolo_depth; player_globals->pannolo_depth = global_pannolo_depth; global_pannolo_slide_value = (-(int32_t) global_pannolo_depth * run_envelope(avctx, &player_globals->pannolo_env, global_pannolo_rate, 0)) >> 7; global_panning = (uint8_t) player_globals->global_panning; global_pannolo_slide_value -= player_globals->pannolo_slide; if ((int16_t) (global_pannolo_slide_value += global_panning) < 0) global_pannolo_slide_value = 0; if (global_pannolo_slide_value > 255) global_pannolo_slide_value = 255; player_globals->global_panning = global_pannolo_slide_value; player_globals->pannolo_slide -= global_panning - global_pannolo_slide_value; } EXECUTE_EFFECT(user_sync) { } static void se_vibrato_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t vibrato_slide_value) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; uint32_t old_frequency = player_channel->frequency; player_channel->frequency -= player_channel->vibrato_slide; if (vibrato_slide_value < 0) { vibrato_slide_value = -vibrato_slide_value; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_up(avctx, player_channel, player_channel->frequency, vibrato_slide_value); else amiga_slide_up(player_channel, player_channel->frequency, vibrato_slide_value); } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) { linear_slide_down(avctx, player_channel, player_channel->frequency, vibrato_slide_value); } else { amiga_slide_down(player_channel, player_channel->frequency, vibrato_slide_value); } player_channel->vibrato_slide -= old_frequency - player_channel->frequency; } static void se_arpegio_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const int16_t arpeggio_transpose, uint8_t arpeggio_finetune) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_frequency, old_frequency; uint16_t octave; int16_t note; int32_t finetune = arpeggio_finetune; octave = arpeggio_transpose / 12; note = arpeggio_transpose % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (finetune * (int32_t) next_frequency) >> 8; old_frequency = player_channel->frequency; slide_frequency = player_channel->arpeggio_slide + old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_frequency) >> (24 - octave); player_channel->arpeggio_slide += old_frequency - frequency; } static void se_tremolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t tremolo_slide_value) { uint16_t volume = player_channel->volume; tremolo_slide_value -= player_channel->tremolo_slide; if ((int16_t) (tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_channel->tremolo_slide -= volume - tremolo_slide_value; } static void se_pannolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t pannolo_slide_value) { uint16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_channel->pannolo_slide; if ((int16_t) (pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_channel->pannolo_slide -= panning - pannolo_slide_value; } #define EXECUTE_SYNTH_CODE_INSTRUCTION(fx_type) \ static uint16_t se_##fx_type(AVSequencerContext *const avctx, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t virtual_channel, \ uint16_t synth_code_line, \ const int src_var, \ int dst_var, \ uint16_t instruction_data, \ const int synth_type) EXECUTE_SYNTH_CODE_INSTRUCTION(stop) { instruction_data += player_channel->variable[src_var]; if (instruction_data & 0x8000) player_channel->stop_forbid_mask &= ~instruction_data; else player_channel->stop_forbid_mask |= instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(kill) { instruction_data += player_channel->variable[src_var]; player_channel->kill_count[synth_type] = instruction_data; player_channel->synth_flags |= 1 << synth_type; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(wait) { instruction_data += player_channel->variable[src_var]; player_channel->wait_count[synth_type] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitvol) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitpan) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~1; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitsld) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~2; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitspc) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~3; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jump) { instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpeq) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpne) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppl) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpmi) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumplt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumple) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpgt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!(synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpge) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpls) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if ((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumphi) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvol) { if (!(player_channel->stop_forbid_mask & 1)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[0] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppan) { if (!(player_channel->stop_forbid_mask & 2)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[1] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpsld) { if (!(player_channel->stop_forbid_mask & 4)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[2] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpspc) { if (!(player_channel->stop_forbid_mask & 8)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[3] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(call) { player_channel->variable[dst_var] = synth_code_line; instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(ret) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = --synth_code_line; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(posvar) { player_channel->variable[src_var] += synth_code_line + --instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(load) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(add) { uint16_t flags = 0; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int32_t) player_channel->variable[dst_var] + (int32_t) instruction_data; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; player_channel->variable[dst_var] = add_data; if (player_channel->variable[dst_var] < instruction_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (!add_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(addx) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; uint32_t add_unsigned_data; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int32_t) player_channel->variable[dst_var] + (int32_t) instruction_data; add_unsigned_data = instruction_data; if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND) { add_data++; add_unsigned_data++; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) ++instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } else if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } player_channel->variable[dst_var] = add_data; if ((player_channel->variable[dst_var] < add_unsigned_data)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (add_data) flags &= ~AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(sub) { uint16_t flags = 0; @@ -7606,1025 +7606,1026 @@ EXECUTE_SYNTH_CODE_INSTRUCTION(gettrml) player_channel->variable[dst_var] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(gettrmp) { instruction_data += player_channel->variable[src_var] + player_channel->tremolo_pos; player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(getpanw) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; const AVSequencerSynthWave *waveform = player_channel->pannolo_waveform; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform == waveform_list[waveform_num]) { instruction_data += waveform_num; break; } } player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(getpanv) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->pannolo_waveform)) { uint32_t waveform_pos = instruction_data % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) player_channel->variable[dst_var] = ((uint8_t *) waveform->data)[waveform_pos] << 8; else player_channel->variable[dst_var] = waveform->data[waveform_pos]; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(getpanl) { const AVSequencerSynthWave *waveform; if ((waveform = player_channel->pannolo_waveform)) { uint16_t waveform_length = -1; if (waveform->samples < 0x10000) waveform_length = waveform->samples; instruction_data += player_channel->variable[src_var] + waveform_length; player_channel->variable[dst_var] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(getpanp) { instruction_data += player_channel->variable[src_var] + player_channel->pannolo_pos; player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(getrnd) { uint32_t seed; instruction_data += player_channel->variable[src_var]; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; player_channel->variable[dst_var] = ((uint64_t) seed * instruction_data) >> 32; return synth_code_line; } /** Sine table for very fast sine calculation. Value is sin(x)*32767 with one element being one degree. */ static const int16_t sine_lut[] = { 0, 571, 1143, 1714, 2285, 2855, 3425, 3993, 4560, 5125, 5689, 6252, 6812, 7370, 7927, 8480, 9031, 9580, 10125, 10667, 11206, 11742, 12274, 12803, 13327, 13847, 14364, 14875, 15383, 15885, 16383, 16876, 17363, 17846, 18323, 18794, 19259, 19719, 20173, 20620, 21062, 21497, 21925, 22347, 22761, 23169, 23570, 23964, 24350, 24729, 25100, 25464, 25820, 26168, 26509, 26841, 27165, 27480, 27787, 28086, 28377, 28658, 28931, 29195, 29450, 29696, 29934, 30162, 30381, 30590, 30790, 30981, 31163, 31335, 31497, 31650, 31793, 31927, 32050, 32164, 32269, 32363, 32448, 32522, 32587, 32642, 32687, 32722, 32747, 32762, 32767, 32762, 32747, 32722, 32687, 32642, 32587, 32522, 32448, 32363, 32269, 32164, 32050, 31927, 31793, 31650, 31497, 31335, 31163, 30981, 30790, 30590, 30381, 30162, 29934, 29696, 29450, 29195, 28931, 28658, 28377, 28086, 27787, 27480, 27165, 26841, 26509, 26168, 25820, 25464, 25100, 24729, 24350, 23964, 23570, 23169, 22761, 22347, 21925, 21497, 21062, 20620, 20173, 19719, 19259, 18794, 18323, 17846, 17363, 16876, 16383, 15885, 15383, 14875, 14364, 13847, 13327, 12803, 12274, 11742, 11206, 10667, 10125, 9580, 9031, 8480, 7927, 7370, 6812, 6252, 5689, 5125, 4560, 3993, 3425, 2855, 2285, 1714, 1143, 571, 0, -571, -1143, -1714, -2285, -2855, -3425, -3993, -4560, -5125, -5689, -6252, -6812, -7370, -7927, -8480, -9031, -9580, -10125, -10667, -11206, -11742, -12274, -12803, -13327, -13847, -14364, -14875, -15383, -15885, -16383, -16876, -17363, -17846, -18323, -18794, -19259, -19719, -20173, -20620, -21062, -21497, -21925, -22347, -22761, -23169, -23570, -23964, -24350, -24729, -25100, -25464, -25820, -26168, -26509, -26841, -27165, -27480, -27787, -28086, -28377, -28658, -28931, -29195, -29450, -29696, -29934, -30162, -30381, -30590, -30790, -30981, -31163, -31335, -31497, -31650, -31793, -31927, -32050, -32164, -32269, -32363, -32448, -32522, -32587, -32642, -32687, -32722, -32747, -32762, -32767, -32762, -32747, -32722, -32687, -32642, -32587, -32522, -32448, -32363, -32269, -32164, -32050, -31927, -31793, -31650, -31497, -31335, -31163, -30981, -30790, -30590, -30381, -30162, -29934, -29696, -29450, -29195, -28931, -28658, -28377, -28086, -27787, -27480, -27165, -26841, -26509, -26168, -25820, -25464, -25100, -24729, -24350, -23964, -23570, -23169, -22761, -22347, -21925, -21497, -21062, -20620, -20173, -19719, -19259, -18794, -18323, -17846, -17363, -16876, -16383, -15885, -15383, -14875, -14364, -13847, -13327, -12803, -12274, -11742, -11206, -10667, -10125, -9580, -9031, -8480, -7927, -7370, -6812, -6252, -5689, -5125, -4560, -3993, -3425, -2855, -2285, -1714, -1143, -571 }; EXECUTE_SYNTH_CODE_INSTRUCTION(getsine) { int16_t degrees; instruction_data += player_channel->variable[src_var]; degrees = (int16_t) instruction_data % 360; if (degrees < 0) degrees += 360; player_channel->variable[dst_var] = (avctx->sine_lut ? avctx->sine_lut[degrees] : sine_lut[degrees]); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(portaup) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->porta_up; player_channel->porta_up = instruction_data; player_channel->portamento += instruction_data; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_up(avctx, player_channel, player_channel->frequency, instruction_data); else amiga_slide_up(player_channel, player_channel->frequency, instruction_data); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(portadn) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->porta_dn; player_channel->porta_dn = instruction_data; player_channel->portamento -= instruction_data; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_down(avctx, player_channel, player_channel->frequency, instruction_data); else amiga_slide_down(player_channel, player_channel->frequency, instruction_data); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibspd) { instruction_data += player_channel->variable[src_var]; player_channel->vibrato_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibdpth) { instruction_data += player_channel->variable[src_var]; player_channel->vibrato_depth = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->vibrato_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->vibrato_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->vibrato_waveform)) player_channel->vibrato_pos = instruction_data % waveform->samples; else player_channel->vibrato_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibrato) { const AVSequencerSynthWave *waveform; uint16_t vibrato_rate; int16_t vibrato_depth; instruction_data += player_channel->variable[src_var]; if (!(vibrato_rate = (instruction_data >> 8))) vibrato_rate = player_channel->vibrato_rate; player_channel->vibrato_rate = vibrato_rate; vibrato_depth = (instruction_data & 0xFF) << 2; if (!vibrato_depth) vibrato_depth = player_channel->vibrato_depth; player_channel->vibrato_depth = vibrato_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t vibrato_slide_value; waveform_pos = player_channel->vibrato_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) vibrato_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else vibrato_slide_value = waveform->data[waveform_pos]; vibrato_slide_value *= -vibrato_depth; vibrato_slide_value >>= 7 - 2; player_channel->vibrato_pos = (waveform_pos + vibrato_rate) % waveform->samples; se_vibrato_do(avctx, player_channel, vibrato_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(vibval) { int32_t vibrato_slide_value; instruction_data += player_channel->variable[src_var]; vibrato_slide_value = (int16_t) instruction_data; se_vibrato_do(avctx, player_channel, vibrato_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(arpspd) { instruction_data += player_channel->variable[src_var]; player_channel->arpeggio_speed = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(arpwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->arpeggio_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->arpeggio_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(arpwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->arpeggio_waveform)) player_channel->arpeggio_pos = instruction_data % waveform->samples; else player_channel->arpeggio_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(arpegio) { const AVSequencerSynthWave *const waveform = player_channel->arpeggio_waveform; if (waveform) { uint16_t arpeggio_speed; int16_t arpeggio_transpose; uint8_t arpeggio_finetune; const uint32_t waveform_pos = player_channel->arpeggio_pos % waveform->samples; instruction_data += player_channel->variable[src_var]; if (!(arpeggio_speed = (instruction_data >> 8))) arpeggio_speed = player_channel->arpeggio_speed; player_channel->arpeggio_speed = arpeggio_speed; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) { arpeggio_finetune = 0; arpeggio_transpose = ((int8_t *) waveform->data)[waveform_pos]; } else { arpeggio_speed = waveform->data[waveform_pos]; arpeggio_finetune = arpeggio_speed; arpeggio_transpose = (int16_t) arpeggio_speed >> 8; } player_channel->arpeggio_finetune = arpeggio_finetune; player_channel->arpeggio_transpose = arpeggio_transpose; player_channel->arpeggio_pos = (waveform_pos + arpeggio_speed) % waveform->samples; se_arpegio_do(avctx, player_channel, arpeggio_transpose, arpeggio_finetune + instruction_data); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(arpval) { int16_t arpeggio_transpose; uint8_t arpeggio_finetune; instruction_data += player_channel->variable[src_var]; player_channel->arpeggio_finetune = arpeggio_finetune = instruction_data; player_channel->arpeggio_transpose = arpeggio_transpose = (int16_t) instruction_data >> 8; se_arpegio_do(avctx, player_channel, arpeggio_transpose, arpeggio_finetune); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; const AVSequencerSynthWave *waveform = NULL; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->sample_waveform = waveform = waveform_list[waveform_num]; break; } } if (waveform) { AVMixerData *mixer; uint16_t flags, repeat_mode, playback_flags; player_channel->sample_waveform = waveform; player_channel->mixer.pos = 0; player_channel->mixer.pos_one_shoot = 0; player_channel->mixer.len = waveform->samples; player_channel->mixer.data = waveform->data; flags = waveform->flags; if (flags & AVSEQ_SYNTH_WAVE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = waveform->sustain_repeat; player_channel->mixer.repeat_length = waveform->sustain_rep_len; player_channel->mixer.repeat_count = waveform->sustain_rep_count; repeat_mode = waveform->sustain_repeat_mode; flags = (~flags >> 1); } else { player_channel->mixer.repeat_start = waveform->repeat; player_channel->mixer.repeat_length = waveform->rep_len; player_channel->mixer.repeat_count = waveform->rep_count; repeat_mode = waveform->repeat_mode; } player_channel->mixer.repeat_counted = 0; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) player_channel->mixer.bits_per_sample = 8; else player_channel->mixer.bits_per_sample = 16; playback_flags = player_channel->mixer.flags & (AVSEQ_MIXER_CHANNEL_FLAG_SURROUND|AVSEQ_MIXER_CHANNEL_FLAG_PLAY); if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if (!(flags & AVSEQ_SYNTH_WAVE_FLAG_NOLOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_SYNTH; player_channel->mixer.flags = playback_flags; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, virtual_channel); if (mixer->mixctx->get_channel) mixer->mixctx->get_channel(mixer, &player_channel->mixer, virtual_channel); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(isetwav) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; const AVSequencerSynthWave *waveform = NULL; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->sample_waveform = waveform = waveform_list[waveform_num]; break; } } if (waveform) { AVMixerData *mixer; uint16_t flags, repeat_mode, playback_flags; player_channel->sample_waveform = waveform; player_channel->mixer.pos = 0; player_channel->mixer.pos_one_shoot = 0; player_channel->mixer.len = waveform->samples; player_channel->mixer.data = waveform->data; flags = waveform->flags; if (flags & AVSEQ_SYNTH_WAVE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = waveform->sustain_repeat; player_channel->mixer.repeat_length = waveform->sustain_rep_len; player_channel->mixer.repeat_count = waveform->sustain_rep_count; repeat_mode = waveform->sustain_repeat_mode; flags = (~flags >> 1); } else { player_channel->mixer.repeat_start = waveform->repeat; player_channel->mixer.repeat_length = waveform->rep_len; player_channel->mixer.repeat_count = waveform->rep_count; repeat_mode = waveform->repeat_mode; } player_channel->mixer.repeat_counted = 0; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) player_channel->mixer.bits_per_sample = 8; else player_channel->mixer.bits_per_sample = 16; playback_flags = player_channel->mixer.flags & (AVSEQ_MIXER_CHANNEL_FLAG_SURROUND|AVSEQ_MIXER_CHANNEL_FLAG_PLAY); if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if (!(flags & AVSEQ_SYNTH_WAVE_FLAG_NOLOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, virtual_channel); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setwavp) { instruction_data += player_channel->variable[src_var]; - player_channel->mixer.pos = instruction_data; + player_channel->mixer.pos = instruction_data; + player_channel->mixer.pos_one_shoot = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setrans) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave; int16_t note; int8_t finetune; player_channel->final_note = (instruction_data += player_channel->variable[src_var] + player_channel->sample_note); note = (int16_t) instruction_data % 12; octave = (int16_t) instruction_data / 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_channel->finetune) < 0) { note--; finetune += -0x80; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += ((int32_t) finetune * (int32_t) next_frequency) >> 7; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> ((24+4) - octave); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setnote) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave; int16_t note; int8_t finetune; instruction_data += player_channel->variable[src_var]; note = (int16_t) instruction_data % 12; octave = (int16_t) instruction_data / 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_channel->finetune) < 0) { note--; finetune += -0x80; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += ((int32_t) finetune * (int32_t) next_frequency) >> 7; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> ((24+4) - octave); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setptch) { uint32_t frequency = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) frequency += player_channel->variable[dst_var]; else frequency += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; player_channel->frequency = frequency; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setper) { uint32_t period = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) period += player_channel->variable[dst_var]; else period += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; if (period) player_channel->frequency = AVSEQ_SLIDE_CONST / period; else player_channel->frequency = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(reset) { instruction_data += player_channel->variable[src_var]; if (!(instruction_data & 0x01)) player_channel->arpeggio_slide = 0; if (!(instruction_data & 0x02)) player_channel->vibrato_slide = 0; if (!(instruction_data & 0x04)) player_channel->tremolo_slide = 0; if (!(instruction_data & 0x08)) player_channel->pannolo_slide = 0; if (!(instruction_data & 0x10)) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; int32_t portamento_value = player_channel->portamento; if (portamento_value < 0) { portamento_value = -portamento_value; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_down(avctx, player_channel, player_channel->frequency, portamento_value); else amiga_slide_down(player_channel, player_channel->frequency, portamento_value); } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) { linear_slide_up(avctx, player_channel, player_channel->frequency, portamento_value); } else { amiga_slide_up(player_channel, player_channel->frequency, portamento_value); } } if (!(instruction_data & 0x20)) player_channel->portamento = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volslup) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_up; player_channel->vol_sl_up = instruction_data; if ((slide_volume += instruction_data) < instruction_data) slide_volume = 0xFFFF; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volsldn) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_dn; player_channel->vol_sl_dn = instruction_data; if (slide_volume < instruction_data) instruction_data = slide_volume; slide_volume -= instruction_data; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmspd) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmdpth) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->tremolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->tremolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->tremolo_waveform)) player_channel->tremolo_pos = instruction_data % waveform->samples; else player_channel->tremolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(tremolo) { const AVSequencerSynthWave *waveform; uint16_t tremolo_rate; int16_t tremolo_depth; instruction_data += player_channel->variable[src_var]; if (!(tremolo_rate = (instruction_data >> 8))) tremolo_rate = player_channel->tremolo_rate; player_channel->tremolo_rate = tremolo_rate; tremolo_depth = (instruction_data & 0xFF) << 2; if (!tremolo_depth) tremolo_depth = player_channel->tremolo_depth; player_channel->tremolo_depth = tremolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t tremolo_slide_value; waveform_pos = player_channel->tremolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) tremolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else tremolo_slide_value = waveform->data[waveform_pos]; tremolo_slide_value *= -tremolo_depth; tremolo_slide_value >>= 7 - 2; player_channel->tremolo_pos = (waveform_pos + tremolo_rate) % waveform->samples; se_tremolo_do(avctx, player_channel, tremolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmval) { int32_t tremolo_slide_value; instruction_data += player_channel->variable[src_var]; tremolo_slide_value = (int16_t) instruction_data; se_tremolo_do(avctx, player_channel, tremolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panleft) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_left; player_channel->pan_sl_left = instruction_data; if (panning < instruction_data) instruction_data = panning; panning -= instruction_data; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panrght) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_right; player_channel->pan_sl_right = instruction_data; if ((panning += instruction_data) < instruction_data) panning = 0xFFFF; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panspd) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pandpth) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_depth = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->pannolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->pannolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->pannolo_waveform)) player_channel->pannolo_pos = instruction_data % waveform->samples; else player_channel->pannolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pannolo) { const AVSequencerSynthWave *waveform; uint16_t pannolo_rate; int16_t pannolo_depth; instruction_data += player_channel->variable[src_var]; if (!(pannolo_rate = (instruction_data >> 8))) pannolo_rate = player_channel->pannolo_rate; player_channel->pannolo_rate = pannolo_rate; pannolo_depth = (instruction_data & 0xFF) << 2; if (!pannolo_depth) pannolo_depth = player_channel->pannolo_depth; player_channel->pannolo_depth = pannolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t pannolo_slide_value; waveform_pos = player_channel->pannolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) pannolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else pannolo_slide_value = waveform->data[waveform_pos]; pannolo_slide_value *= -pannolo_depth; pannolo_slide_value >>= 7 - 2; player_channel->pannolo_pos = (waveform_pos + pannolo_rate) % waveform->samples; se_pannolo_do(avctx, player_channel, pannolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panval) { int32_t pannolo_slide_value; instruction_data += player_channel->variable[src_var]; pannolo_slide_value = (int16_t) instruction_data; se_pannolo_do(avctx, player_channel, pannolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(nop) { return synth_code_line; } static void process_row(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { uint32_t current_tick; AVSequencerSong *song = avctx->player_song; uint16_t counted = 0; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; current_tick = player_host_channel->tempo_counter; current_tick++; if (current_tick >= ((uint32_t) player_host_channel->fine_pattern_delay + player_host_channel->tempo)) current_tick = 0; if (!(player_host_channel->tempo_counter = current_tick)) { const AVSequencerTrack *track; const AVSequencerOrderList *const order_list = song->order_list + channel; AVSequencerOrderData *order_data; const AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t pattern_delay, row, last_row, track_length; uint32_t ord = -1; if (player_channel->host_channel == channel) { const uint32_t slide_value = player_host_channel->arpeggio_freq; player_host_channel->arpeggio_freq = 0; player_channel->frequency += slide_value; } player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO); AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); player_host_channel->effect = NULL; player_host_channel->arpeggio_tick = 0; player_host_channel->note_delay = 0; if ((pattern_delay = player_host_channel->pattern_delay) && (pattern_delay > player_host_channel->pattern_delay_count++)) return; player_host_channel->pattern_delay_count = 0; player_host_channel->pattern_delay = 0; row = player_host_channel->row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP; order_data = player_host_channel->order; track = player_host_channel->track; goto loop_to_row; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; order_data = player_host_channel->order; if ((player_host_channel->chg_pattern < song->tracks) && ((track = song->track_list[player_host_channel->chg_pattern]))) { if (!(avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN)) player_host_channel->track = track; goto loop_to_row; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) goto get_new_pattern; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) { if (!row--) goto get_new_pattern; } else if (++row >= player_host_channel->max_row) { get_new_pattern: order_data = player_host_channel->order; if (avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN) { track = player_host_channel->track; goto loop_to_row; } ord = -1; if (order_data) { while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; }
BastyCDGS/ffmpeg-soc
a728dc8cc67124d58361650aa5aab52328d7afee
Fixed (multi) note retrigger in AVSequencer player at least for XM/IT modules. Also some small nit fixes.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index fdd1774..e242e40 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -2584,1113 +2584,1113 @@ EXECUTE_EFFECT(fine_portamento_down) player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = data_word; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = v5; } } EXECUTE_EFFECT(portamento_up_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); portamento_up_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(portamento_down_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); portamento_down_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_portamento_up_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_up_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->fine_tone_porta; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = v4; player_host_channel->tone_porta_once = v8; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(fine_portamento_down_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_down_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->fine_tone_porta; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v3; player_host_channel->tone_porta_once = v5; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->fine_tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v0; player_host_channel->tone_porta_once = v1; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = data_word; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(note_slide) { uint16_t note_slide_value, note_slide_type; if (!(note_slide_value = (uint8_t) data_word)) note_slide_value = player_host_channel->note_slide; player_host_channel->note_slide = note_slide_value; if (!(note_slide_type = (data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; player_host_channel->note_slide_type = note_slide_type; if (!(note_slide_type & 0x10)) note_slide_value = -note_slide_value; note_slide_value += player_host_channel->final_note; player_host_channel->final_note = note_slide_value; if (player_channel->host_channel == channel) player_channel->frequency = get_tone_pitch(avctx, player_host_channel, player_channel, note_slide_value); } EXECUTE_EFFECT(vibrato) { uint16_t vibrato_rate; int16_t vibrato_depth; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; vibrato_depth = (int8_t) data_word; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, vibrato_depth << 2); } EXECUTE_EFFECT(fine_vibrato) { uint16_t vibrato_rate; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, (int8_t) data_word); } EXECUTE_EFFECT(do_key_off) { if (data_word <= player_host_channel->tempo_counter) play_key_off(player_channel); } EXECUTE_EFFECT(hold_delay) { // TODO: Implement hold delay effect } EXECUTE_EFFECT(note_fade) { if (data_word <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } EXECUTE_EFFECT(note_cut) { if ((data_word & 0xFFF) <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) { player_channel->volume = 0; player_channel->sub_volume = 0; if (data_word & 0xF000) { player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_channel->mixer.flags = 0; } } } } EXECUTE_EFFECT(note_delay) { } EXECUTE_EFFECT(tremor) { uint8_t tremor_off, tremor_on; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; if (!(tremor_off = (uint8_t) data_word)) tremor_off = player_host_channel->tremor_off_ticks; player_host_channel->tremor_off_ticks = tremor_off; if (!(tremor_on = (data_word >> 8))) tremor_on = player_host_channel->tremor_on_ticks; player_host_channel->tremor_on_ticks = tremor_on; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON)) tremor_off = tremor_on; if (player_host_channel->tremor_count-- <= 1) { player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON; player_host_channel->tremor_count = tremor_off; } } } EXECUTE_EFFECT(note_retrigger) { - uint16_t retrigger_tick = data_word & 0x7FFF, retrigger_tick_count; + uint16_t retrigger_tick = data_word & 0x7FFF, retrigger_tick_count = player_host_channel->retrig_tick_count; - if ((data_word & 0x8000) && data_word) - retrigger_tick = player_host_channel->tempo / retrigger_tick; + if (data_word & 0x8000) + retrigger_tick = player_host_channel->tempo / (retrigger_tick ? retrigger_tick : 1); - if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --retrigger_tick) { - if (retrigger_tick <= retrigger_tick_count) - retrigger_tick_count = -1; - } else if (player_channel->host_channel == channel) { - player_channel->mixer.pos = 0; + if (retrigger_tick_count-- <= 1) { + retrigger_tick_count = retrigger_tick; + + if (player_channel->host_channel == channel) + player_channel->mixer.pos = 0; } - player_host_channel->retrig_tick_count = ++retrigger_tick_count; + player_host_channel->retrig_tick_count = retrigger_tick_count; } EXECUTE_EFFECT(multi_retrigger_note) { uint8_t multi_retrigger_tick, multi_retrigger_volume_change; uint16_t retrigger_tick_count; uint32_t volume; if (!(multi_retrigger_tick = (data_word >> 8))) multi_retrigger_tick = player_host_channel->multi_retrig_tick; player_host_channel->multi_retrig_tick = multi_retrigger_tick; if (!(multi_retrigger_volume_change = (uint8_t) data_word)) multi_retrigger_volume_change = player_host_channel->multi_retrig_vol_chg; player_host_channel->multi_retrig_vol_chg = multi_retrigger_volume_change; - if ((retrigger_tick_count = player_host_channel->retrig_tick_count) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE) || (player_channel->host_channel != channel)) { + if (((retrigger_tick_count = player_host_channel->retrig_tick_count) > 1) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE) || (player_channel->host_channel != channel)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; } else if ((int8_t) multi_retrigger_volume_change < 0) { uint8_t multi_retrigger_scale = 4; if (!(avctx->player_song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES)) multi_retrigger_scale = player_host_channel->multi_retrig_scale; if ((int8_t) (multi_retrigger_volume_change -= 0xBF) >= 0) { volume = multi_retrigger_volume_change * multi_retrigger_scale; if (player_channel->volume >= volume) { player_channel->volume -= volume; } else { player_channel->volume = 0; player_channel->sub_volume = 0; } } else { volume = ((multi_retrigger_volume_change + 0x40) * multi_retrigger_scale) + player_channel->volume; if (volume < 0x100) { - player_channel->volume = volume; + player_channel->volume = volume; } else { player_channel->volume = 0xFF; player_channel->sub_volume = 0xFF; } } - } else { + } else if ((int8_t) multi_retrigger_volume_change > 0) { uint8_t volume_multiplier, volume_divider; - volume = (player_channel->volume << 8); + volume = player_channel->volume << 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) volume += player_channel->sub_volume; if ((volume_multiplier = (multi_retrigger_volume_change >> 4))) volume *= volume_multiplier; if ((volume_divider = (multi_retrigger_volume_change & 0xF))) volume /= volume_divider; if (volume > 0xFFFF) volume = 0xFFFF; player_channel->volume = volume >> 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) player_channel->sub_volume = volume; } - if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --multi_retrigger_tick) { - if (multi_retrigger_tick <= retrigger_tick_count) - retrigger_tick_count = -1; - } else if (player_channel->host_channel == channel) { - player_channel->mixer.pos = 0; + if (retrigger_tick_count-- <= 1) { + retrigger_tick_count = multi_retrigger_tick; + + if (player_channel->host_channel == channel) + player_channel->mixer.pos = 0; } - player_host_channel->retrig_tick_count = ++retrigger_tick_count; + player_host_channel->retrig_tick_count = retrigger_tick_count; } EXECUTE_EFFECT(extended_ctrl) { const AVSequencerModule *module; AVSequencerPlayerChannel *scan_player_channel; uint8_t extended_control_byte; uint16_t virtual_channel; const uint16_t extended_control_word = data_word & 0x0FFF; switch (data_word >> 12) { case 0 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; if (!extended_control_word) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; break; case 1 : player_host_channel->glissando = extended_control_word; break; case 2 : extended_control_byte = extended_control_word; switch (extended_control_word >> 8) { case 0 : if (!extended_control_byte) extended_control_byte = 1; if (extended_control_byte > 4) extended_control_byte = 4; player_host_channel->multi_retrig_scale = extended_control_byte; break; case 1 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; if (extended_control_byte) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; break; case 2 : if (extended_control_byte) player_host_channel->multi_retrig_tick = player_host_channel->tempo / extended_control_byte; break; } break; case 3 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->mixer.flags = 0; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 4 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 5 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) play_key_off(scan_player_channel); scan_player_channel++; } while (++virtual_channel < module->channels); break; case 6 : player_host_channel->sub_slide = extended_control_word; break; } } EXECUTE_EFFECT(invert_loop) { // TODO: Implement invert loop } EXECUTE_EFFECT(exec_fx) { } EXECUTE_EFFECT(stop_fx) { uint8_t stop_fx = data_word; if ((int8_t) stop_fx < 0) stop_fx = 127; if (!(data_word >>= 8)) data_word = player_host_channel->exec_fx; if (data_word >= player_host_channel->tempo_counter) player_host_channel->effects_used[(stop_fx >> 3)] |= (1 << (7 - (stop_fx & 7))); } EXECUTE_EFFECT(set_volume) { player_host_channel->tremolo_slide = 0; if (check_old_volume(avctx, player_channel, &data_word, channel)) { player_channel->volume = data_word >> 8; player_channel->sub_volume = data_word; } } EXECUTE_EFFECT(volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_ok(player_host_channel, data_word); volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_ok(player_host_channel, data_word); volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->fine_vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_once_ok(player_host_channel, data_word); fine_volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_once_ok(player_host_channel, data_word); fine_volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_to) { uint8_t volume_slide_to_value, volume_slide_to_volume; if (!(volume_slide_to_value = (uint8_t) data_word)) volume_slide_to_value = player_host_channel->volume_slide_to; player_host_channel->volume_slide_to = volume_slide_to_value; player_host_channel->volume_slide_to_slide &= 0x00FF; player_host_channel->volume_slide_to_slide += volume_slide_to_value << 8; volume_slide_to_volume = data_word >> 8; if (volume_slide_to_volume && (volume_slide_to_volume < 0xFF)) { player_host_channel->volume_slide_to_volume = volume_slide_to_volume; } else if (volume_slide_to_volume && (player_channel->host_channel == channel)) { const uint16_t volume_slide_target = (volume_slide_to_volume << 8) + player_host_channel->volume_slide_to_volume; uint16_t volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume < volume_slide_target) { do_volume_slide(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target <= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } else { do_volume_slide_down(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target >= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } } } EXECUTE_EFFECT(tremolo) { const AVSequencerSong *const song = avctx->player_song; int16_t tremolo_slide_value; uint8_t tremolo_rate; int16_t tremolo_depth; if (!(tremolo_rate = (data_word >> 8))) tremolo_rate = player_host_channel->tremolo_rate; player_host_channel->tremolo_rate = tremolo_rate; if (!(tremolo_depth = (int8_t) data_word)) tremolo_depth = player_host_channel->tremolo_depth; player_host_channel->tremolo_depth = tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (tremolo_depth > 63) tremolo_depth = 63; if (tremolo_depth < -63) tremolo_depth = -63; } tremolo_slide_value = (-(int32_t) tremolo_depth * run_envelope(avctx, &player_host_channel->tremolo_env, tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) tremolo_slide_value <<= 2; if (player_channel->host_channel == channel) { const uint16_t volume = player_channel->volume; tremolo_slide_value -= player_host_channel->tremolo_slide; if ((int16_t) (tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_host_channel->tremolo_slide -= volume - tremolo_slide_value; } } EXECUTE_EFFECT(set_track_volume) { if (check_old_track_volume(avctx, &data_word)) { player_host_channel->track_volume = data_word >> 8; player_host_channel->track_sub_volume = data_word; } } EXECUTE_EFFECT(track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_host_channel->track_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_up; v5 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_vol_slide_up = data_word; player_host_channel->track_vol_slide_down = v3; player_host_channel->fine_trk_vol_slide_up = v4; player_host_channel->fine_trk_vol_slide_dn = v5; } EXECUTE_EFFECT(track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_host_channel->track_vol_slide_down; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v3 = player_host_channel->fine_trk_vol_slide_up; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = data_word; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = data_word; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_dn; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v3 = player_host_channel->fine_trk_vol_slide_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = data_word; } EXECUTE_EFFECT(track_volume_slide_to) { uint8_t track_vol_slide_to, track_volume_slide_to_volume; if (!(track_vol_slide_to = (uint8_t) data_word)) track_vol_slide_to = player_host_channel->track_vol_slide_to; player_host_channel->track_vol_slide_to = track_vol_slide_to; player_host_channel->track_vol_slide_to_slide &= 0x00FF; player_host_channel->track_vol_slide_to_slide += track_vol_slide_to << 8; track_volume_slide_to_volume = data_word >> 8; if (track_volume_slide_to_volume && (track_volume_slide_to_volume < 0xFF)) { player_host_channel->track_vol_slide_to = track_volume_slide_to_volume; } else if (track_volume_slide_to_volume) { const uint16_t track_volume_slide_target = (track_volume_slide_to_volume << 8) + player_host_channel->track_vol_slide_to_sub_volume; uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume < track_volume_slide_target) { do_track_volume_slide(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target <= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } else { do_track_volume_slide_down(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target >= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } } } EXECUTE_EFFECT(track_tremolo) { const AVSequencerSong *const song = avctx->player_song; int16_t track_tremolo_slide_value; uint8_t track_tremolo_rate; int16_t track_tremolo_depth; uint16_t track_volume; if (!(track_tremolo_rate = (data_word >> 8))) track_tremolo_rate = player_host_channel->track_trem_rate; player_host_channel->track_trem_rate = track_tremolo_rate; if (!(track_tremolo_depth = (int8_t) data_word)) track_tremolo_depth = player_host_channel->track_trem_depth; player_host_channel->track_trem_depth = track_tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (track_tremolo_depth > 63) track_tremolo_depth = 63; if (track_tremolo_depth < -63) track_tremolo_depth = -63; } track_tremolo_slide_value = (-(int32_t) track_tremolo_depth * run_envelope(avctx, &player_host_channel->track_trem_env, track_tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) track_tremolo_slide_value <<= 2; track_volume = player_host_channel->track_volume; track_tremolo_slide_value -= player_host_channel->track_trem_slide; if ((int16_t) (track_tremolo_slide_value += track_volume) < 0) track_tremolo_slide_value = 0; if (track_tremolo_slide_value > 255) track_tremolo_slide_value = 255; player_host_channel->track_volume = track_tremolo_slide_value; player_host_channel->track_trem_slide -= track_volume - track_tremolo_slide_value; } EXECUTE_EFFECT(set_panning) { const uint8_t panning = data_word >> 8; if (player_channel->host_channel == channel) { player_channel->panning = panning; player_channel->sub_panning = data_word; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = data_word; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = data_word; } @@ -8047,2181 +8047,2181 @@ EXECUTE_SYNTH_CODE_INSTRUCTION(isetwav) player_channel->mixer.data = waveform->data; flags = waveform->flags; if (flags & AVSEQ_SYNTH_WAVE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = waveform->sustain_repeat; player_channel->mixer.repeat_length = waveform->sustain_rep_len; player_channel->mixer.repeat_count = waveform->sustain_rep_count; repeat_mode = waveform->sustain_repeat_mode; flags = (~flags >> 1); } else { player_channel->mixer.repeat_start = waveform->repeat; player_channel->mixer.repeat_length = waveform->rep_len; player_channel->mixer.repeat_count = waveform->rep_count; repeat_mode = waveform->repeat_mode; } player_channel->mixer.repeat_counted = 0; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) player_channel->mixer.bits_per_sample = 8; else player_channel->mixer.bits_per_sample = 16; playback_flags = player_channel->mixer.flags & (AVSEQ_MIXER_CHANNEL_FLAG_SURROUND|AVSEQ_MIXER_CHANNEL_FLAG_PLAY); if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if (!(flags & AVSEQ_SYNTH_WAVE_FLAG_NOLOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, virtual_channel); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setwavp) { instruction_data += player_channel->variable[src_var]; player_channel->mixer.pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setrans) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave; int16_t note; int8_t finetune; player_channel->final_note = (instruction_data += player_channel->variable[src_var] + player_channel->sample_note); note = (int16_t) instruction_data % 12; octave = (int16_t) instruction_data / 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_channel->finetune) < 0) { note--; finetune += -0x80; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += ((int32_t) finetune * (int32_t) next_frequency) >> 7; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> ((24+4) - octave); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setnote) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave; int16_t note; int8_t finetune; instruction_data += player_channel->variable[src_var]; note = (int16_t) instruction_data % 12; octave = (int16_t) instruction_data / 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_channel->finetune) < 0) { note--; finetune += -0x80; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += ((int32_t) finetune * (int32_t) next_frequency) >> 7; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> ((24+4) - octave); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setptch) { uint32_t frequency = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) frequency += player_channel->variable[dst_var]; else frequency += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; player_channel->frequency = frequency; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setper) { uint32_t period = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) period += player_channel->variable[dst_var]; else period += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; if (period) player_channel->frequency = AVSEQ_SLIDE_CONST / period; else player_channel->frequency = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(reset) { instruction_data += player_channel->variable[src_var]; if (!(instruction_data & 0x01)) player_channel->arpeggio_slide = 0; if (!(instruction_data & 0x02)) player_channel->vibrato_slide = 0; if (!(instruction_data & 0x04)) player_channel->tremolo_slide = 0; if (!(instruction_data & 0x08)) player_channel->pannolo_slide = 0; if (!(instruction_data & 0x10)) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; int32_t portamento_value = player_channel->portamento; if (portamento_value < 0) { portamento_value = -portamento_value; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_down(avctx, player_channel, player_channel->frequency, portamento_value); else amiga_slide_down(player_channel, player_channel->frequency, portamento_value); } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) { linear_slide_up(avctx, player_channel, player_channel->frequency, portamento_value); } else { amiga_slide_up(player_channel, player_channel->frequency, portamento_value); } } if (!(instruction_data & 0x20)) player_channel->portamento = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volslup) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_up; player_channel->vol_sl_up = instruction_data; if ((slide_volume += instruction_data) < instruction_data) slide_volume = 0xFFFF; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volsldn) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_dn; player_channel->vol_sl_dn = instruction_data; if (slide_volume < instruction_data) instruction_data = slide_volume; slide_volume -= instruction_data; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmspd) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmdpth) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->tremolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->tremolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->tremolo_waveform)) player_channel->tremolo_pos = instruction_data % waveform->samples; else player_channel->tremolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(tremolo) { const AVSequencerSynthWave *waveform; uint16_t tremolo_rate; int16_t tremolo_depth; instruction_data += player_channel->variable[src_var]; if (!(tremolo_rate = (instruction_data >> 8))) tremolo_rate = player_channel->tremolo_rate; player_channel->tremolo_rate = tremolo_rate; tremolo_depth = (instruction_data & 0xFF) << 2; if (!tremolo_depth) tremolo_depth = player_channel->tremolo_depth; player_channel->tremolo_depth = tremolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t tremolo_slide_value; waveform_pos = player_channel->tremolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) tremolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else tremolo_slide_value = waveform->data[waveform_pos]; tremolo_slide_value *= -tremolo_depth; tremolo_slide_value >>= 7 - 2; player_channel->tremolo_pos = (waveform_pos + tremolo_rate) % waveform->samples; se_tremolo_do(avctx, player_channel, tremolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmval) { int32_t tremolo_slide_value; instruction_data += player_channel->variable[src_var]; tremolo_slide_value = (int16_t) instruction_data; se_tremolo_do(avctx, player_channel, tremolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panleft) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_left; player_channel->pan_sl_left = instruction_data; if (panning < instruction_data) instruction_data = panning; panning -= instruction_data; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panrght) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_right; player_channel->pan_sl_right = instruction_data; if ((panning += instruction_data) < instruction_data) panning = 0xFFFF; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panspd) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pandpth) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_depth = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->pannolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->pannolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->pannolo_waveform)) player_channel->pannolo_pos = instruction_data % waveform->samples; else player_channel->pannolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pannolo) { const AVSequencerSynthWave *waveform; uint16_t pannolo_rate; int16_t pannolo_depth; instruction_data += player_channel->variable[src_var]; if (!(pannolo_rate = (instruction_data >> 8))) pannolo_rate = player_channel->pannolo_rate; player_channel->pannolo_rate = pannolo_rate; pannolo_depth = (instruction_data & 0xFF) << 2; if (!pannolo_depth) pannolo_depth = player_channel->pannolo_depth; player_channel->pannolo_depth = pannolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t pannolo_slide_value; waveform_pos = player_channel->pannolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) pannolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else pannolo_slide_value = waveform->data[waveform_pos]; pannolo_slide_value *= -pannolo_depth; pannolo_slide_value >>= 7 - 2; player_channel->pannolo_pos = (waveform_pos + pannolo_rate) % waveform->samples; se_pannolo_do(avctx, player_channel, pannolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panval) { int32_t pannolo_slide_value; instruction_data += player_channel->variable[src_var]; pannolo_slide_value = (int16_t) instruction_data; se_pannolo_do(avctx, player_channel, pannolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(nop) { return synth_code_line; } static void process_row(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { uint32_t current_tick; AVSequencerSong *song = avctx->player_song; uint16_t counted = 0; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; current_tick = player_host_channel->tempo_counter; current_tick++; if (current_tick >= ((uint32_t) player_host_channel->fine_pattern_delay + player_host_channel->tempo)) current_tick = 0; if (!(player_host_channel->tempo_counter = current_tick)) { const AVSequencerTrack *track; const AVSequencerOrderList *const order_list = song->order_list + channel; AVSequencerOrderData *order_data; const AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t pattern_delay, row, last_row, track_length; uint32_t ord = -1; if (player_channel->host_channel == channel) { const uint32_t slide_value = player_host_channel->arpeggio_freq; player_host_channel->arpeggio_freq = 0; player_channel->frequency += slide_value; } player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO); AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); player_host_channel->effect = NULL; player_host_channel->arpeggio_tick = 0; player_host_channel->note_delay = 0; - player_host_channel->retrig_tick_count = 0; if ((pattern_delay = player_host_channel->pattern_delay) && (pattern_delay > player_host_channel->pattern_delay_count++)) return; player_host_channel->pattern_delay_count = 0; player_host_channel->pattern_delay = 0; row = player_host_channel->row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP; order_data = player_host_channel->order; track = player_host_channel->track; goto loop_to_row; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; order_data = player_host_channel->order; if ((player_host_channel->chg_pattern < song->tracks) && ((track = song->track_list[player_host_channel->chg_pattern]))) { if (!(avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN)) player_host_channel->track = track; goto loop_to_row; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) goto get_new_pattern; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) { if (!row--) goto get_new_pattern; } else if (++row >= player_host_channel->max_row) { get_new_pattern: order_data = player_host_channel->order; if (avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN) { track = player_host_channel->track; goto loop_to_row; } ord = -1; if (order_data) { while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; } } check_next_empty_order: do { ord++; if ((ord >= order_list->orders) || !(order_data = order_list->order_data[ord])) { song_end_found: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if ((order_list->rep_start >= order_list->orders) || !(order_data = order_list->order_data[order_list->rep_start])) { disable_channel: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; player_host_channel->tempo = 0; return; } if (order_data->flags & (AVSEQ_ORDER_DATA_FLAG_END_ORDER|AVSEQ_ORDER_DATA_FLAG_END_SONG)) goto disable_channel; row = 0; if (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT)) goto disable_channel; if ((track = order_data->track)) break; } if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_ORDER) goto song_end_found; if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_SONG) { if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) goto disable_channel; goto song_end_found; } } while (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT) || !(track = order_data->track)); player_host_channel->order = order_data; player_host_channel->track = track; if (player_host_channel->gosub_depth < order_data->played) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) player_host_channel->tempo = 0; } order_data->played++; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; loop_to_row: track_length = track->last_row; row = order_data->first_row; last_row = order_data->last_row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; row = player_host_channel->break_row; if (track_length < row) row = order_data->first_row; } if (track_length < row) goto check_next_empty_order; if (track_length < last_row) last_row = track_length; player_host_channel->max_row = last_row + 1; if ((pattern_delay = order_data->tempo)) player_host_channel->tempo = pattern_delay; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) row = last_row - row; } player_host_channel->row = row; if ((int) ((player_host_channel->track->data) + row)->note == AVSEQ_TRACK_DATA_NOTE_END) { if (++counted) goto get_new_pattern; goto disable_channel; } } } static const AVSequencerPlayerEffects fx_lut[128] = { {arpeggio, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {fine_tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {note_slide, NULL, check_note_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {fine_vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {do_key_off, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {hold_delay, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_fade, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_cut, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_delay, preset_note_delay, NULL, 0x00, 0x00, 0x0000}, {tremor, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_retrigger, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {multi_retrigger_note, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {extended_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {invert_loop, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {exec_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {stop_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {volume_slide_up, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {volume_slide_down, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_volume_slide_up, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {fine_volume_slide_down, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, 0x00, 0x01, 0x0000}, {set_track_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {track_volume_slide_up, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_volume_slide_down, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_volume_slide_up, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {fine_track_volume_slide_down, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {track_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {panning_slide_left, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {panning_slide_right, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_panning_slide_left, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {fine_panning_slide_right, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_track_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {track_panning_slide_left, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_panning_slide_right, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_panning_slide_left, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {fine_track_panning_slide_right, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {track_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {set_relative_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_break, NULL, NULL, 0x00, 0x02, 0x0000}, {position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {relative_position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {change_pattern, NULL, NULL, 0x00, 0x02, 0x0000}, {reverse_pattern_play, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {fine_pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_loop, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub_return, NULL, NULL, 0x00, 0x02, 0x0000}, {channel_sync, NULL, NULL, 0x00, 0x02, 0x0000}, {set_sub_slides, NULL, NULL, 0x00, 0x02, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {sample_offset_high, NULL, NULL, 0x00, 0x01, 0x0000}, {sample_offset_low, NULL, NULL, 0x00, 0x01, 0x0000}, {set_hold, NULL, NULL, 0x00, 0x01, 0x0000}, {set_decay, NULL, NULL, 0x00, 0x01, 0x0000}, {set_transpose, preset_set_transpose, NULL, 0x00, 0x01, 0x0000}, {instrument_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {instrument_change, NULL, NULL, 0x00, 0x01, 0x0000}, {synth_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_synth_value, NULL, NULL, 0x00, 0x01, 0x0000}, {envelope_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_envelope_value, NULL, NULL, 0x00, 0x01, 0x0000}, {nna_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {loop_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_speed, NULL, NULL, 0x00, 0x00, 0x0000}, {speed_slide_faster, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {speed_slide_slower, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_speed_slide_faster, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {fine_speed_slide_slower, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {speed_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {spenolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {spenolo, NULL, NULL, 0x00, 0x00, 0x0000}, {channel_ctrl, NULL, check_channel_control, 0x00, 0x00, 0x0000}, {set_global_volume, NULL, NULL, 0x00, 0x00, 0x0000}, {global_volume_slide_up, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_volume_slide_down, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_volume_slide_up, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {fine_global_volume_slide_down, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {global_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, 0x00, 0x00, 0x0000}, {set_global_panning, NULL, NULL, 0x00, 0x00, 0x0000}, {global_panning_slide_left, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_panning_slide_right, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_panning_slide_left, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {fine_global_panning_slide_right, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {global_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {global_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_pannolo, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {user_sync, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0000} }; static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerTrack *track; const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *track_data; uint32_t fx = -1; if (!(track = player_host_channel->track)) return; track_data = track->data + player_host_channel->row; if ((track_fx = player_host_channel->effect)) { while (++fx < track_data->effects) { if (track_fx == track_data->effects_data[fx]) break; } } else if (track_data->effects) { fx = 0; track_fx = track_data->effects_data[0]; } else { track_fx = NULL; } player_host_channel->effect = track_fx; if ((fx < track_data->effects) && track_data->effects_data[fx]) { do { const int fx_byte = track_fx->command & 0x7F; if (fx_byte == AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = track_fx->data; if (player_host_channel->tempo_counter < player_host_channel->exec_fx) break; } } while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))); if (player_host_channel->effect != track_fx) { player_host_channel->effect = track_fx; AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*pre_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); const int fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; if ((pre_fx_func = effects_lut->pre_pattern_func)) pre_fx_func(avctx, player_host_channel, player_channel, channel, track_fx->data); } } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= (player_host_channel->sample == player_channel->sample); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= (player_host_channel->sample == player_channel->sample); return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; - if (nna_volume || !(nna = player_host_channel->nna)) + if (nna_volume || !player_channel->final_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope *(**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope *(**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; player_channel->global_instr_volume = instrument->global_volume; player_channel->volume_swing = instrument->volume_swing; volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } - player_channel->auto_vibrato_sweep = sample->vibrato_sweep; - player_channel->auto_tremolo_sweep = sample->tremolo_sweep; - player_channel->auto_pannolo_sweep = sample->pannolo_sweep; - player_channel->auto_vibrato_depth = sample->vibrato_depth; - player_channel->auto_vibrato_rate = sample->vibrato_rate; - player_channel->auto_tremolo_depth = sample->tremolo_depth; - player_channel->auto_tremolo_rate = sample->tremolo_rate; - player_channel->auto_pannolo_depth = sample->pannolo_depth; - player_channel->auto_pannolo_rate = sample->pannolo_rate; - player_channel->auto_vibrato_count = 0; - player_channel->auto_tremolo_count = 0; - player_channel->auto_pannolo_count = 0; - player_channel->auto_vibrato_freq = 0; - player_channel->auto_tremolo_vol = 0; - player_channel->auto_pannolo_pan = 0; - player_channel->slide_env_freq = 0; - player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; - player_host_channel->arpeggio_freq = 0; - player_host_channel->vibrato_slide = 0; - player_host_channel->tremolo_slide = 0; + player_channel->auto_vibrato_sweep = sample->vibrato_sweep; + player_channel->auto_tremolo_sweep = sample->tremolo_sweep; + player_channel->auto_pannolo_sweep = sample->pannolo_sweep; + player_channel->auto_vibrato_depth = sample->vibrato_depth; + player_channel->auto_vibrato_rate = sample->vibrato_rate; + player_channel->auto_tremolo_depth = sample->tremolo_depth; + player_channel->auto_tremolo_rate = sample->tremolo_rate; + player_channel->auto_pannolo_depth = sample->pannolo_depth; + player_channel->auto_pannolo_rate = sample->pannolo_rate; + player_channel->auto_vibrato_count = 0; + player_channel->auto_tremolo_count = 0; + player_channel->auto_pannolo_count = 0; + player_channel->auto_vibrato_freq = 0; + player_channel->auto_tremolo_vol = 0; + player_channel->auto_pannolo_pan = 0; + player_channel->slide_env_freq = 0; + player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; + player_host_channel->retrig_tick_count = 0; + player_host_channel->arpeggio_freq = 0; + player_host_channel->vibrato_slide = 0; + player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) - flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; + flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) - flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; + flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; } player_channel->pitch_pan_separation = instrument->pitch_pan_separation; player_channel->pitch_pan_center = instrument->pitch_pan_center; player_channel->panning_swing = instrument->panning_swing; panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } player_channel->note_swing = instrument->note_swing; player_channel->pitch_swing = instrument->pitch_swing; } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose;
BastyCDGS/ffmpeg-soc
29cefa785396bc48c8bb25d103cac21237c8e824
Fixed small nit in AVSequencer player in arpeggio handling.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 7205552..fdd1774 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -1894,1026 +1894,1025 @@ static void do_volume_slide_down(const AVSequencerContext *const avctx, player_channel->sub_volume = slide_volume; } } static void volume_slide_up_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v3, v4, v5; v3 = player_host_channel->vol_slide_down; v4 = player_host_channel->fine_vol_slide_up; v5 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->vol_slide_up = data_word; player_host_channel->vol_slide_down = v3; player_host_channel->fine_vol_slide_up = v4; player_host_channel->fine_vol_slide_down = v5; } static void volume_slide_down_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v3, v4; v0 = player_host_channel->vol_slide_up; v3 = player_host_channel->fine_vol_slide_up; v4 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = data_word; player_host_channel->fine_vol_slide_up = v3; player_host_channel->fine_vol_slide_down = v4; } static void fine_volume_slide_up_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v4; v0 = player_host_channel->vol_slide_up; v1 = player_host_channel->vol_slide_down; v4 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = v1; player_host_channel->fine_vol_slide_up = data_word; player_host_channel->fine_vol_slide_down = v4; } static void fine_volume_slide_down_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3; v0 = player_host_channel->vol_slide_up; v1 = player_host_channel->vol_slide_down; v3 = player_host_channel->fine_vol_slide_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = v1; player_host_channel->fine_vol_slide_up = data_word; player_host_channel->fine_vol_slide_down = v3; } static uint32_t check_old_track_volume(const AVSequencerContext *const avctx, uint16_t *const data_word) { const AVSequencerSong *const song = avctx->player_song; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (*data_word < 0x4000) *data_word = ((*data_word & 0xFF00) << 2) | (*data_word & 0xFF); else *data_word = 0xFFFF; } return 1; } static void do_track_volume_slide(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if ((track_volume += data_word) < data_word) track_volume = 0xFFFF; player_host_channel->track_volume = track_volume >> 8; player_host_channel->track_sub_volume = track_volume; } } static void do_track_volume_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume < data_word) data_word = track_volume; track_volume -= data_word; player_host_channel->track_volume = track_volume >> 8; player_host_channel->track_sub_volume = track_volume; } } static void do_panning_slide(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, uint16_t data_word, const uint16_t channel) { if (player_channel->host_channel == channel) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < data_word) data_word = panning; panning -= data_word; player_host_channel->track_panning = player_channel->panning = panning >> 8; player_host_channel->track_sub_panning = player_channel->sub_panning = panning; } else { uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning < data_word) data_word = track_panning; track_panning -= data_word; player_host_channel->track_panning = track_panning >> 8; player_host_channel->track_sub_panning = track_panning; } player_host_channel->track_note_panning = player_host_channel->track_panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning; } static void do_panning_slide_right(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t data_word, const uint16_t channel) { if (player_channel->host_channel == channel) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if ((panning += data_word) < data_word) panning = 0xFFFF; player_host_channel->track_panning = player_channel->panning = panning >> 8; player_host_channel->track_sub_panning = player_channel->sub_panning = panning; } else { uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if ((track_panning += data_word) < data_word) track_panning = 0xFFFF; player_host_channel->track_panning = track_panning >> 8; player_host_channel->track_sub_panning = track_panning; } player_host_channel->track_note_panning = player_host_channel->track_panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning; } static void do_track_panning_slide(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { uint16_t channel_panning = ((uint8_t) player_host_channel->channel_panning << 8) + player_host_channel->channel_sub_panning; if (channel_panning < data_word) data_word = channel_panning; channel_panning -= data_word; player_host_channel->channel_panning = channel_panning >> 8; player_host_channel->channel_sub_panning = channel_panning; } static void do_track_panning_slide_right(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { uint16_t channel_panning = ((uint8_t) player_host_channel->channel_panning << 8) + player_host_channel->channel_sub_panning; if ((channel_panning += data_word) < data_word) channel_panning = 0xFFFF; player_host_channel->channel_panning = channel_panning >> 8; player_host_channel->channel_sub_panning = channel_panning; } static uint32_t check_surround_track_panning(AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const uint8_t channel_ctrl_byte) { if (player_channel->host_channel == channel) { if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) return 1; if (channel_ctrl_byte) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; else player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (channel_ctrl_byte) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } return 0; } static uint16_t *get_speed_address(const AVSequencerContext *const avctx, const uint16_t speed_type, uint16_t *const speed_min_value, uint16_t *const speed_max_value) { const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_adr; switch (speed_type & 0x07) { case 0x00 : *speed_min_value = song->bpm_speed_min; *speed_max_value = song->bpm_speed_max; speed_adr = (uint16_t *) &player_globals->bpm_speed; break; case 0x01 : *speed_min_value = song->bpm_tempo_min; *speed_max_value = song->bpm_tempo_max; speed_adr = (uint16_t *) &player_globals->bpm_tempo; break; case 0x02 : *speed_min_value = song->spd_min; *speed_max_value = song->spd_max; speed_adr = (uint16_t *) &player_globals->spd_speed; break; case 0x07 : *speed_min_value = 1; *speed_max_value = 0xFFFF; speed_adr = (uint16_t *) &player_globals->speed_mul; break; default : *speed_min_value = 0; *speed_max_value = 0; speed_adr = NULL; break; } return speed_adr; } /** Old SoundTracker tempo definition table. */ static const uint32_t old_st_lut[] = { 192345259, 96192529, 64123930, 48096264, 38475419, 32061964, 27482767, 24048132, 21687744, 19240098 }; static void speed_val_ok(const AVSequencerContext *const avctx, uint16_t *const speed_adr, uint16_t speed_value, const uint8_t speed_type, const uint16_t speed_min_value, const uint16_t speed_max_value) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; if (speed_value < speed_min_value) speed_value = speed_min_value; if (speed_value > speed_max_value) speed_value = speed_max_value; if ((speed_type & 0x07) == 0x07) { player_globals->speed_mul = speed_value >> 8; player_globals->speed_div = speed_value; } else { *speed_adr = speed_value; } if (!((player_globals->speed_type = speed_type) & 0x08)) { AVMixerData *mixer = avctx->player_mixer_data; uint64_t tempo = 0; uint8_t speed_multiplier; switch (speed_type & 0x07) { case 0x00 : player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING; break; case 0x02 : player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING; break; } if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING) { if (player_globals->spd_speed > 10) { tempo = (uint32_t) 989156 * player_globals->spd_speed; if ((speed_multiplier = player_globals->speed_mul)) tempo *= speed_multiplier; if ((speed_multiplier = player_globals->speed_div)) tempo /= speed_multiplier; } else { tempo = (avctx->old_st_lut ? avctx->old_st_lut[player_globals->spd_speed] : old_st_lut[player_globals->spd_speed]); } } else { tempo = (player_globals->bpm_speed) * (player_globals->bpm_tempo) << 16; if ((speed_multiplier = player_globals->speed_mul)) tempo *= speed_multiplier; if ((speed_multiplier = player_globals->speed_div)) tempo /= speed_multiplier; } player_globals->tempo = tempo; tempo *= player_globals->relative_speed; tempo >>= 16; if (mixer->mixctx->set_tempo) mixer->mixctx->set_tempo(mixer, tempo); } } static void do_speed_slide(const AVSequencerContext *const avctx, uint16_t data_word) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_min_value, speed_max_value; if ((speed_ptr = get_speed_address(avctx, player_globals->speed_type, &speed_min_value, &speed_max_value))) { uint16_t speed_value; if ((player_globals->speed_type & 0x07) == 0x07) speed_value = (player_globals->speed_mul << 8) + player_globals->speed_div; else speed_value = *speed_ptr; if ((speed_value += data_word) < data_word) speed_value = 0xFFFF; speed_val_ok(avctx, speed_ptr, speed_value, player_globals->speed_type, speed_min_value, speed_max_value); } } static void do_speed_slide_slower(const AVSequencerContext *const avctx, uint16_t data_word) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_min_value, speed_max_value; if ((speed_ptr = get_speed_address(avctx, player_globals->speed_type, &speed_min_value, &speed_max_value))) { uint16_t speed_value; if ((player_globals->speed_type & 0x07) == 0x07) speed_value = (player_globals->speed_mul << 8) + player_globals->speed_div; else speed_value = *speed_ptr; if (speed_value < data_word) data_word = speed_value; speed_value -= data_word; speed_val_ok(avctx, speed_ptr, speed_value, player_globals->speed_type, speed_min_value, speed_max_value); } } static void do_global_volume_slide(const AVSequencerContext *const avctx, AVSequencerPlayerGlobals *const player_globals, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if ((global_volume += data_word) < data_word) global_volume = 0xFFFF; player_globals->global_volume = global_volume >> 8; player_globals->global_sub_volume = global_volume; } } static void do_global_volume_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerGlobals *const player_globals, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume < data_word) data_word = global_volume; global_volume -= data_word; player_globals->global_volume = global_volume >> 8; player_globals->global_sub_volume = global_volume; } } static void do_global_panning_slide(AVSequencerPlayerGlobals *const player_globals, uint16_t data_word) { uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; if ((global_panning += data_word) < data_word) global_panning = 0xFFFF; player_globals->global_panning = global_panning >> 8; player_globals->global_sub_panning = global_panning; } static void do_global_panning_slide_right(AVSequencerPlayerGlobals *const player_globals, uint16_t data_word) { uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; if (global_panning < data_word) data_word = global_panning; global_panning -= data_word; player_globals->global_panning = global_panning >> 8; player_globals->global_sub_panning = global_panning; } #define EXECUTE_EFFECT(fx_type) \ static void fx_type(AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ const unsigned fx_byte, \ uint16_t data_word) EXECUTE_EFFECT(arpeggio) { int8_t first_arpeggio, second_arpeggio; int16_t arpeggio_value; if (!data_word) data_word = (player_host_channel->arpeggio_first << 8) + player_host_channel->arpeggio_second; player_host_channel->arpeggio_first = first_arpeggio = data_word >> 8; player_host_channel->arpeggio_second = second_arpeggio = data_word; switch (player_host_channel->arpeggio_tick) { case 0 : arpeggio_value = 0; break; case 1 : arpeggio_value = first_arpeggio; break; default : - arpeggio_value = second_arpeggio; - + arpeggio_value = second_arpeggio; player_host_channel->arpeggio_tick -= 3; break; } if (player_channel->host_channel == channel) { uint32_t frequency, arpeggio_freq, old_frequency; uint16_t octave; int16_t note; octave = arpeggio_value / 12; note = arpeggio_value % 12; if (note < 0) { octave--; note += 12; } old_frequency = player_channel->frequency; frequency = old_frequency + player_host_channel->arpeggio_freq; arpeggio_freq = (avctx->frequency_lut ? avctx->frequency_lut[note + 1] : pitch_lut[note + 1]); arpeggio_freq = ((uint64_t) frequency * arpeggio_freq) >> (24 - octave); player_host_channel->arpeggio_freq += old_frequency - arpeggio_freq; player_channel->frequency = arpeggio_freq; } player_host_channel->arpeggio_tick++; } EXECUTE_EFFECT(portamento_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_up; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_up_ok(player_host_channel, data_word); portamento_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(portamento_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_down; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_down_ok(player_host_channel, data_word); portamento_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_portamento_up) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_up; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = data_word; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->tone_porta_once; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = data_word; player_host_channel->tone_porta_once = v4; player_host_channel->fine_tone_porta_once = v8; } } EXECUTE_EFFECT(fine_portamento_down) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = data_word; v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up = data_word; v0 = v1; v3 = v4; v5 = v8; } player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->tone_porta_once; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = data_word; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = v5; } } EXECUTE_EFFECT(portamento_up_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); portamento_up_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(portamento_down_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); portamento_down_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_portamento_up_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_up_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->fine_tone_porta; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = v4; player_host_channel->tone_porta_once = v8; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(fine_portamento_down_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_down_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->fine_tone_porta; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v3; player_host_channel->tone_porta_once = v5; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->fine_tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v0; player_host_channel->tone_porta_once = v1; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } }
BastyCDGS/ffmpeg-soc
a300dd5a7bff19c549bd5c32bebef86651a71c52
Fixed some small nits in AVSequencer player header file.
diff --git a/libavsequencer/player.h b/libavsequencer/player.h index 6022e72..9022bf2 100644 --- a/libavsequencer/player.h +++ b/libavsequencer/player.h @@ -1480,582 +1480,590 @@ enum AVSequencerPlayerChannelCondVar { /** AVSequencerPlayerChannel->use_nna_flags bitfield. */ enum AVSequencerPlayerChannelUseNNAFlags { AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA = 0x01, ///< Use NNA trigger entry field for volume AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA = 0x02, ///< Use NNA trigger entry field for panning AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA = 0x04, ///< Use NNA trigger entry field for slide AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA = 0x08, ///< Use NNA trigger entry field for special AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA = 0x10, ///< Use NNA trigger entry field for volume AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA = 0x20, ///< Use NNA trigger entry field for panning AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA = 0x40, ///< Use NNA trigger entry field for slide AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA = 0x80, ///< Use NNA trigger entry field for special }; /** AVSequencerPlayerChannel->use_sustain_flags bitfield. */ enum AVSequencerPlayerChannelUseSustainFlags { AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME = 0x01, ///< Use sustain entry position field for volume AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING = 0x02, ///< Use sustain entry position field for panning AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE = 0x04, ///< Use sustain entry position field for slide AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL = 0x08, ///< Use sustain entry position field for special AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME_KEEP = 0x10, ///< Keep sustain entry position for volume AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING_KEEP = 0x20, ///< Keep sustain entry position for panning AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE_KEEP = 0x40, ///< Keep sustain entry position for slide AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL_KEEP = 0x80, ///< Keep sustain entry position for special }; /** AVSequencerPlayerChannel->synth_flags bitfield. */ enum AVSequencerPlayerChannelSynthFlags { AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_VOLUME = 0x0001, ///< Volume handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_PANNING = 0x0002, ///< Panning handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_SLIDE = 0x0004, ///< Slide handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_SPECIAL = 0x0008, ///< Special handling code is running KILL }; /** * Player virtual channel data structure used by playback engine for * processing the virtual channels which are the true internal * channels associated by the tracks taking the new note actions * (NNAs) into account so one host channel can have none to multiple * virtual channels. This also contains the synth sound processing * stuff since these operate mostly on virtual channels. This * structure is actually for one virtual channel and therefore * actually pointed as an array with size of number of virtual * channels. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerChannel { /** Mixer channel data responsible for this virtual channel. This will be passed to the actual mixer which calculates the final audio data. */ AVMixerChannel mixer; /** Pointer to player instrument definition for the current virtual channel for obtaining instrument stuff. */ const AVSequencerInstrument *instrument; /** Pointer to player sound sample definition for the current virtual channel for obtaining sample data. */ const AVSequencerSample *sample; /** Current output frequency in Hz of currently playing sample or waveform. This will be forwarded after relative pitch scaling to the mixer channel data. */ uint32_t frequency; /** Current sample volume of currently playing sample or waveform for this virtual channel. */ uint8_t volume; /** Current sample sub-volume of currently playing sample or waveform. This is basically volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t sub_volume; /** Current instrument global volume multiplied with current sample global volume of currently playing instrument being played by this virtual channel. */ uint16_t instr_volume; /** Current sample panning position of currently playing sample or waveform for this virtual channel. */ int8_t panning; /** Current sample sub-panning of currently playing sample or waveform. This is basically panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t sub_panning; /** Current final volume level of currently playing sample or waveform for this virtual channel as it will be forwarded to the mixer channel data. */ uint8_t final_volume; /** Current final panning of currently playing sample or waveform for this virtual channel as it will be forwarded to the mixer channel data. */ int8_t final_panning; /** Current sample global volume of currently playing sample or waveform for this virtual channel. */ uint8_t global_volume; /** Current sample global sub-volume of currently playing sample or waveform. This is basically global volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t global_sub_volume; /** Current sample global panning position of currently playing sample or waveform for this virtual channel. */ int8_t global_panning; /** Current sample global sub-panning of currently playing sample or waveform. This is basically global panning divided by 256, but sub-panning doesn't account into actual mixer output. */ uint8_t global_sub_panning; /** Current instrument global volume of currently playing instrument for this virtual channel. */ uint8_t global_instr_volume; /** Current random note swing in semi-tones. This value will cause a flip between each play of this instrument making it sounding more natural. */ uint8_t note_swing; /** Current random volume swing in 1/256th steps (i.e. 256 means 100%). The volume will vibrate randomnessly around that volume percentage and make the instrument sound more like a naturally played one. */ uint16_t volume_swing; /** Current random panning swing in 1/256th steps (i.e. 256 means 100%). This will cause the stereo position to vary a bit each instrument play to make it sound more like a naturally played one. */ uint16_t panning_swing; /** Current random pitch swing in 1/65536th steps, i.e. 65536 means 100%. This will cause the stereo position to vary a bit each instrument play to make it sound more like a naturally played one. */ uint32_t pitch_swing; /** Current host channel to which this virtual channel is mapped to, i.e. the creator of this virtual channel. */ uint16_t host_channel; /** Player virtual channel flags. This stores certain information about the current virtual channel based upon the host channel which allocated this virtual channel. The virtual channels are allocated according to the new note action (NNA) mechanism. */ int16_t flags; /** Current player volume envelope for the current virtual channel. */ AVSequencerPlayerEnvelope vol_env; /** Current player panning envelope for the current virtual channel. */ AVSequencerPlayerEnvelope pan_env; /** Current player slide envelope for the current virtual channel. */ AVSequencerPlayerEnvelope slide_env; /** Pointer to player envelope data interpreted as resonance filter for the current virtual channel. */ AVSequencerPlayerEnvelope resonance_env; /** Current player auto vibrato envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_vib_env; /** Current player auto tremolo envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_trem_env; /** Current player auto pannolo / panbrello envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_pan_env; /** Current slide envelope relative to played sample frequency to be able to undo the previous slide envelope frequency. */ int32_t slide_env_freq; /** Current auto vibrato frequency relative to played sample frequency to be able to undo the previous auto vibrato frequency changes. */ int32_t auto_vibrato_freq; /** Current auto tremolo volume level relative to played sample volume to be able to undo the previous auto tremolo volume changes. */ int16_t auto_tremolo_vol; /** Current auto pannolo (panbrello) panning position relative to played sample panning to be able to undo the previous auto pannolo panning changes. */ int16_t auto_pannolo_pan; /** Current number of tick for auto vibrato incremented by the auto vibrato sweep rate. */ uint16_t auto_vibrato_count; /** Current number of tick for auto tremolo incremented by the auto tremolo sweep rate. */ uint16_t auto_tremolo_count; /** Current number of tick for auto pannolo (panbrello) incremented by the auto pannolo sweep rate. */ uint16_t auto_pannolo_count; /** Current fade out value which is subtracted each tick with to fade out count value until zero is reached or 0 if fade out is disabled for this virtual channel. */ uint16_t fade_out; /** Current fade out count value where 65535 is the initial value (full volume level) which is subtracted each tick with the fade out value until zero is reached, when the note will be turned off. */ uint16_t fade_out_count; /** Current pitch panning separation. */ int16_t pitch_pan_separation; /** Current pitch panning center (0 is C-0, 1 is C#1, 12 is C-1, 13 is C#1, 24 is C-2, 36 is C-3 and so on. */ uint8_t pitch_pan_center; /** Current decay action when decay is off. */ uint8_t dca; /** Hold value. */ uint16_t hold; /** Decay value. */ uint16_t decay; /** Current auto vibrato sweep. */ uint16_t auto_vibrato_sweep; /** Current auto tremolo sweep. */ uint16_t auto_tremolo_sweep; /** Current auto pannolo (panbrello) sweep. */ uint16_t auto_pannolo_sweep; /** Current auto vibrato depth. */ uint8_t auto_vibrato_depth; /** Current auto vibrato rate (speed). */ uint8_t auto_vibrato_rate; /** Current auto tremolo depth. */ uint8_t auto_tremolo_depth; /** Current auto tremolo rate (speed). */ uint8_t auto_tremolo_rate; /** Current auto pannolo (panbrello) depth. */ uint8_t auto_pannolo_depth; /** Current auto pannolo (panbrello) rate. */ uint8_t auto_pannolo_rate; /** Current instrument note being played (after applying current instrument transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t instr_note; /** Current sample note being played (after applying current sample transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t sample_note; /** Array (of size waveforms) of pointers containing attached waveforms used by this virtual channel. */ AVSequencerSynthWave *const *waveform_list; /** Number of attached waveforms used by this virtual channel. */ uint16_t waveforms; /** Pointer to sequencer sample synth sound currently being played by this virtual channel for obtaining the synth sound code. */ const AVSequencerSynth *synth; /** Pointer to current sample data waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *sample_waveform; /** Pointer to current vibrato waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *vibrato_waveform; /** Pointer to current tremolo waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *tremolo_waveform; /** Pointer to current pannolo (panbrello) waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *pannolo_waveform; /** Pointer to current arpeggio data waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *arpeggio_waveform; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code or 0 if the current sample does not use synth sound. */ uint16_t entry_pos[4]; /** Current sustain entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code. This will position jump the code to the target line number of a key off note is pressed or 0 if the current sample does not use synth sound. */ uint16_t sustain_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when NNA has been triggered. This allows a complete custom new note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t nna_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when DNA has been triggered. This allows a complete custom duplicate note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t dna_pos[4]; /** Current contents of the 16 variable registers (v0-v15). */ uint16_t variable[16]; /** Current status of volume [0], panning [1], slide [2] and special [3] variable condition status register or 0 if the current sample does not use synth sound. */ uint16_t cond_var[4]; /** Current usage of NNA trigger entry fields. This will run custom synth sound code execution on a NNA trigger. */ uint8_t use_nna_flags; /** Current usage of sustain entry position fields. This will run custom synth sound code execution on a note off trigger. */ uint8_t use_sustain_flags; /** Current final note being played (after applying all transpose values, etc.) by the formula: current octave * 12 + current note where C-0 is represented with a value zero. */ int16_t final_note; /** Current sample finetune value in 1/128th of a semitone. */ int8_t finetune; /** Current STOP synth sound instruction forbid / permit mask or 0 if the current sample does not use synth sound. */ uint8_t stop_forbid_mask; /** Current waveform position in samples of the VIBRATO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t vibrato_pos; /** Current waveform position in samples of the TREMOLO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t tremolo_pos; /** Current waveform position in samples of the PANNOLO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t pannolo_pos; /** Current waveform position in samples of the ARPEGIO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t arpeggio_pos; /** Current player channel synth sound flags. The indicate certain status flags for some synth code instructions. Currently they are only defined for the KILL instruction. */ uint16_t synth_flags; /** Current volume [0], panning [1], slide [2] and special [3] KILL count in number of ticks or 0 if the current sample does not use synth sound. */ uint16_t kill_count[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT count in number of ticks or 0 if the current sample does not use synth sound. */ uint16_t wait_count[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT line number to be reached to continue execution or 0 if the current sample does not use synth sound. */ uint16_t wait_line[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT type (0 is WAITVOL, 1 is WAITPAN, 2 is WAITSLD and 3 is WAITSPC) which has to reach the specified target line number before to continue execution or 0 if the current sample does not use synth sound. */ uint8_t wait_type[4]; /** Current PORTAUP synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t porta_up; /** Current PORTADN synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t porta_dn; /** Current PORTAUP and PORTADN synth sound instruction total value, i.e. all PORTAUP and PORTADN instructions added together or 0 if the current sample does not use synth sound. */ int32_t portamento; /** Current VIBRATO synth sound instruction frequency relative to played sample frequency to be able to undo the previous vibrato frequency changes or 0 if the current sample does not use synth sound. */ int32_t vibrato_slide; /** Current VIBRATO synth sound instruction rate value or 0 if the current sample does not use synth sound. */ uint16_t vibrato_rate; /** Current VIBRATO synth sound instruction depth value or 0 if the current sample does not use synth sound. */ int16_t vibrato_depth; /** Current ARPEGIO synth sound instruction frequency relative to played sample frequency to be able to undo the previous arpeggio frequency changes or 0 if the current sample does not use synth sound. */ int32_t arpeggio_slide; /** Current ARPEGIO synth sound instruction speed value or 0 if the current sample does not use synth sound. */ uint16_t arpeggio_speed; /** Current ARPEGIO synth sound instruction transpose value or 0 if the current sample does not use synth sound. */ int8_t arpeggio_transpose; /** Current ARPEGIO synth sound instruction finetuning value in 1/128th of a semitone or 0 if the current sample does not use synth sound. */ int8_t arpeggio_finetune; /** Current VOLSLUP synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t vol_sl_up; /** Current VOLSLDN synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t vol_sl_dn; /** Current TREMOLO synth sound instruction volume level relative to played sample volume to be able to undo the previous tremolo volume changes or 0 if the current sample does not use synth sound. */ int16_t tremolo_slide; /** Current TREMOLO synth sound instruction depth value or 0 if the current sample does not use synth sound. */ int16_t tremolo_depth; /** Current TREMOLO synth sound instruction rate value or 0 if the current sample does not use synth sound. */ uint16_t tremolo_rate; /** Current PANLEFT synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t pan_sl_left; /** Current PANRIGHT synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t pan_sl_right; /** Current PANNOLO synth sound instruction relative slide value or 0 if the current sample does not use synth sound. */ int16_t pannolo_slide; /** Current PANNOLO synth sound instruction depth or 0 if the current sample does not use synth sound. */ int16_t pannolo_depth; /** Current PANNOLO synth sound instruction rate or 0 if the current sample does not use synth sound. */ uint16_t pannolo_rate; } AVSequencerPlayerChannel; #include "libavsequencer/avsequencer.h" /** AVSequencerPlayerEffects->flags bitfield. */ enum AVSequencerPlayerEffectsFlags { AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW = 0x80, ///< Effect will be executed during the whole row instead of only once }; typedef struct AVSequencerPlayerEffects { /** Function pointer to the actual effect to be executed for this effect. Can be NULL if this effect number is unused. This structure is actually for one effect and there actually pointed as an array with size of number of total effects. */ void (*effect_func)(AVSequencerContext *const avctx, - AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, - const uint16_t channel, const unsigned fx_byte, uint16_t data_word); + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + const unsigned fx_byte, uint16_t data_word); /** Function pointer for pre-pattern evaluation. Some effects require a pre-initialization stage. Can be NULL if the effect number either is not used or the effect does not require a pre-initialization stage. */ void (*pre_pattern_func)(const AVSequencerContext *const avctx, - AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, - const uint16_t channel, uint16_t data_word); + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, uint16_t data_word); /** Function pointer for parameter checking for an effect. Can be NULL if the effect number either is not used or the effect does not require pre-checking. */ void (*check_fx_func)(const AVSequencerContext *const avctx, - AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, - const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + uint16_t *const fx_byte, + uint16_t *const data_word, + uint16_t *const flags); /** Special flags for this effect, this currently defines if the effect is executed during the whole row each tick or just only once per row. */ uint8_t flags; /** Logical AND filter mask for the channel control command filtering the affected channel. */ uint8_t and_mask_ctrl; /** Standard execution tick when this effect starts to be executed and there is no execute effect command issued which is in most case tick 0 (immediately) or 1 (skip first tick at row). */ uint16_t std_exec_tick; } AVSequencerPlayerEffects; /** AVSequencerPlayerHook->flags bitfield. */ enum AVSequencerPlayerHookFlags { AVSEQ_PLAYER_HOOK_FLAG_SONG_END = 0x01, ///< Hook is only called when song end is being detected instead of each tick AVSEQ_PLAYER_HOOK_FLAG_BEGINNING = 0x02, ///< Hook is called before executing playback code instead of the end }; /** * Playback handler hook for allowing developers to execute customized * code in the playback handler under certain conditions. Currently * the hook can either be called once at song end found or each tick, * as well as before execution of the playback handler or after it. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerHook { /** Special flags for the hook which decide hook call time and purpose. */ int8_t flags; /** The actual hook function to be called which gets passed the associated AVSequencerContext. */ - void (*hook_func)(AVSequencerContext *avctx, void *hook_data, uint64_t hook_len); + void (*hook_func)(AVSequencerContext *avctx, + void *hook_data, uint64_t hook_len); /** The actual hook data to be passed to the hook function which also gets passed the associated AVSequencerContext and the module and sub-song currently processed (i.e. triggered the hook). */ void *hook_data; /** Size of the hook data passed to the hook function which gets passed the associated AVSequencerContext and the module and sub-song currently processed (i.e. triggered the hook). */ uint64_t hook_len; } AVSequencerPlayerHook; #endif /* AVSEQUENCER_PLAYER_H */
BastyCDGS/ffmpeg-soc
7000cde598956b2e39a4c3568d616f609db5aca5
Fixed some nits in AVSequencer player and instrument handling.
diff --git a/libavsequencer/instr.c b/libavsequencer/instr.c index 9824493..452e355 100644 --- a/libavsequencer/instr.c +++ b/libavsequencer/instr.c @@ -1,1107 +1,1117 @@ /* * Implement AVSequencer instrument management * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Implement AVSequencer instrument management. */ #include "libavutil/log.h" #include "libavformat/avformat.h" #include "libavsequencer/avsequencer.h" static const char *instrument_name(void *p) { AVSequencerInstrument *instrument = p; AVMetadataTag *tag = av_metadata_get(instrument->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Instrument"; } static const AVClass avseq_instrument_class = { "AVSequencer Instrument", instrument_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerInstrument *avseq_instrument_create(void) { return av_mallocz(sizeof(AVSequencerInstrument) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_instrument_destroy(AVSequencerInstrument *instrument) { if (instrument) av_metadata_free(&instrument->metadata); av_free(instrument); } int avseq_instrument_open(AVSequencerModule *module, AVSequencerInstrument *instrument, uint32_t samples) { AVSequencerSample *sample; AVSequencerInstrument **instrument_list; uint32_t i; uint16_t instruments; int res; if (!module) return AVERROR_INVALIDDATA; instrument_list = module->instrument_list; instruments = module->instruments; if (!(instrument && ++instruments)) { return AVERROR_INVALIDDATA; } else if (!(instrument_list = av_realloc(instrument_list, (instruments * sizeof(AVSequencerInstrument *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate instrument storage container.\n"); return AVERROR(ENOMEM); } instrument->av_class = &avseq_instrument_class; for (i = 0; i < samples; ++i) { if (!(sample = avseq_sample_create())) { while (i--) { av_free(instrument->sample_list[i]); } av_log(instrument, AV_LOG_ERROR, "Cannot allocate sample number %d.\n", i + 1); return AVERROR(ENOMEM); } if ((res = avseq_sample_open(instrument, sample, NULL, 0)) < 0) { while (i--) { av_free(instrument->sample_list[i]); } return res; } } instrument->fade_out = 65535; instrument->pitch_pan_center = 4*12; // C-4 instrument->global_volume = 255; instrument->default_panning = -128; instrument->env_usage_flags = ~(AVSEQ_INSTRUMENT_FLAG_USE_VOLUME_ENV|AVSEQ_INSTRUMENT_FLAG_USE_PANNING_ENV|AVSEQ_INSTRUMENT_FLAG_USE_SLIDE_ENV|-0x2000); instrument->filter_cutoff = -1; instrument->filter_damping = -1; instrument_list[instruments - 1] = instrument; module->instrument_list = instrument_list; module->instruments = instruments; return 0; } void avseq_instrument_close(AVSequencerModule *module, AVSequencerInstrument *instrument) { AVSequencerInstrument **instrument_list; uint16_t instruments, i; if (!(module && instrument)) return; instrument_list = module->instrument_list; instruments = module->instruments; for (i = 0; i < instruments; ++i) { if (instrument_list[i] == instrument) break; } if (instruments && (i != instruments)) { AVSequencerInstrument *last_instrument = instrument_list[--instruments]; if (!instruments) { av_freep(&module->instrument_list); module->instruments = 0; } else if (!(instrument_list = av_realloc(instrument_list, (instruments * sizeof(AVSequencerInstrument *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_instruments = i + 1; instrument_list = module->instrument_list; if (copy_instruments < instruments) memmove(instrument_list + i, instrument_list + copy_instruments, (instruments - copy_instruments) * sizeof(AVSequencerInstrument *)); instrument_list[instruments - 1] = NULL; } else { const unsigned copy_instruments = i + 1; if (copy_instruments < instruments) { memmove(instrument_list + i, instrument_list + copy_instruments, (instruments - copy_instruments) * sizeof(AVSequencerInstrument *)); instrument_list[instruments - 1] = last_instrument; } module->instrument_list = instrument_list; module->instruments = instruments; } } i = instrument->samples; while (i--) { AVSequencerSample *sample = instrument->sample_list[i]; avseq_sample_close(instrument, sample); avseq_sample_destroy(sample); } } static const char *envelope_name(void *p) { AVSequencerEnvelope *envelope = p; AVMetadataTag *tag = av_metadata_get(envelope->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Envelope"; } static const AVClass avseq_envelope_class = { "AVSequencer Envelope", envelope_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerEnvelope *avseq_envelope_create(void) { return av_mallocz(sizeof(AVSequencerEnvelope) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_envelope_destroy(AVSequencerEnvelope *envelope) { if (envelope) av_metadata_free(&envelope->metadata); av_free(envelope); } int avseq_envelope_open(AVSequencerContext *avctx, AVSequencerModule *module, AVSequencerEnvelope *envelope, uint32_t points, uint32_t type, uint32_t scale, uint32_t y_offset, uint32_t nodes) { AVSequencerEnvelope **envelope_list; uint16_t envelopes; int res; if (!module) return AVERROR_INVALIDDATA; envelope_list = module->envelope_list; envelopes = module->envelopes; if (!(envelope && ++envelopes)) { return AVERROR_INVALIDDATA; } else if (!(envelope_list = av_realloc(envelope_list, (envelopes * sizeof(AVSequencerEnvelope *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate envelope storage container.\n"); return AVERROR(ENOMEM); } envelope->av_class = &avseq_envelope_class; envelope->value_min = -scale; envelope->value_max = scale; envelope->tempo = 1; if ((res = avseq_envelope_data_open(avctx, envelope, points, type, scale, y_offset, nodes)) < 0) { av_free(envelope_list); return res; } envelope_list[envelopes - 1] = envelope; module->envelope_list = envelope_list; module->envelopes = envelopes; return 0; } void avseq_envelope_close(AVSequencerModule *module, AVSequencerEnvelope *envelope) { AVSequencerEnvelope **envelope_list; uint16_t envelopes, i; if (!(module && envelope)) return; envelope_list = module->envelope_list; envelopes = module->envelopes; for (i = 0; i < envelopes; ++i) { if (envelope_list[i] == envelope) break; } if (envelopes && (i != envelopes)) { AVSequencerEnvelope *last_envelope = envelope_list[--envelopes]; uint16_t j; for (j = 0; i < module->instruments; ++j) { AVSequencerInstrument *instrument = module->instrument_list[j]; unsigned smp; if (instrument->volume_env == envelope) { if (last_envelope != envelope) instrument->volume_env = envelope_list[j + 1]; else if (i) instrument->volume_env = envelope_list[j - 1]; else instrument->volume_env = NULL; } if (instrument->panning_env == envelope) { if (last_envelope != envelope) instrument->panning_env = envelope_list[j + 1]; else if (i) instrument->panning_env = envelope_list[j - 1]; else instrument->panning_env = NULL; } if (instrument->slide_env == envelope) { if (last_envelope != envelope) instrument->slide_env = envelope_list[j + 1]; else if (i) instrument->slide_env = envelope_list[j - 1]; else instrument->slide_env = NULL; } if (instrument->vibrato_env == envelope) { if (last_envelope != envelope) instrument->vibrato_env = envelope_list[j + 1]; else if (i) instrument->vibrato_env = envelope_list[j - 1]; else instrument->vibrato_env = NULL; } if (instrument->tremolo_env == envelope) { if (last_envelope != envelope) instrument->tremolo_env = envelope_list[j + 1]; else if (i) instrument->tremolo_env = envelope_list[j - 1]; else instrument->tremolo_env = NULL; } if (instrument->pannolo_env == envelope) { if (last_envelope != envelope) instrument->pannolo_env = envelope_list[j + 1]; else if (i) instrument->pannolo_env = envelope_list[j - 1]; else instrument->pannolo_env = NULL; } if (instrument->channolo_env == envelope) { if (last_envelope != envelope) instrument->channolo_env = envelope_list[j + 1]; else if (i) instrument->channolo_env = envelope_list[j - 1]; else instrument->channolo_env = NULL; } if (instrument->spenolo_env == envelope) { if (last_envelope != envelope) instrument->spenolo_env = envelope_list[j + 1]; else if (i) instrument->spenolo_env = envelope_list[j - 1]; else instrument->spenolo_env = NULL; } for (smp = 0; smp < instrument->samples; ++smp) { AVSequencerSample *sample = instrument->sample_list[smp]; if (sample->auto_vibrato_env == envelope) { if (last_envelope != envelope) sample->auto_vibrato_env = envelope_list[i + 1]; else if (i) sample->auto_vibrato_env = envelope_list[i - 1]; else sample->auto_vibrato_env = NULL; } if (sample->auto_tremolo_env == envelope) { if (last_envelope != envelope) sample->auto_tremolo_env = envelope_list[i + 1]; else if (i) sample->auto_tremolo_env = envelope_list[i - 1]; else sample->auto_tremolo_env = NULL; } if (sample->auto_pannolo_env == envelope) { if (last_envelope != envelope) sample->auto_pannolo_env = envelope_list[i + 1]; else if (i) sample->auto_pannolo_env = envelope_list[i - 1]; else sample->auto_pannolo_env = NULL; } } } if (!envelopes) { av_freep(&module->envelope_list); module->envelopes = 0; } else if (!(envelope_list = av_realloc(envelope_list, (envelopes * sizeof(AVSequencerEnvelope *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_envelopes = i + 1; envelope_list = module->envelope_list; if (copy_envelopes < envelopes) memmove(envelope_list + i, envelope_list + copy_envelopes, (envelopes - copy_envelopes) * sizeof(AVSequencerEnvelope *)); envelope_list[envelopes - 1] = NULL; } else { const unsigned copy_envelopes = i + 1; if (copy_envelopes < envelopes) { memmove(envelope_list + i, envelope_list + copy_envelopes, (envelopes - copy_envelopes) * sizeof(AVSequencerEnvelope *)); envelope_list[envelopes - 1] = last_envelope; } module->envelope_list = envelope_list; module->envelopes = envelopes; } } avseq_envelope_data_close(envelope); } #define CREATE_ENVELOPE(env_type) \ - static void create_##env_type##_envelope (AVSequencerContext *avctx, \ - int16_t *data, \ - uint32_t points, \ - uint32_t scale, \ - uint32_t scale_type, \ + static void create_##env_type##_envelope (const AVSequencerContext *const avctx, \ + int16_t *data, \ + uint32_t points, \ + uint32_t scale, \ + uint32_t scale_type, \ uint32_t y_offset) CREATE_ENVELOPE(empty) { uint32_t i; for (i = points; i > 0; i--) { *data++ = y_offset; } } /** Sine table for very fast sine calculation. Value is sin(x)*32767 with one element being one degree. */ static const int16_t sine_lut[] = { 0, 571, 1143, 1714, 2285, 2855, 3425, 3993, 4560, 5125, 5689, 6252, 6812, 7370, 7927, 8480, 9031, 9580, 10125, 10667, 11206, 11742, 12274, 12803, 13327, 13847, 14364, 14875, 15383, 15885, 16383, 16876, 17363, 17846, 18323, 18794, 19259, 19719, 20173, 20620, 21062, 21497, 21925, 22347, 22761, 23169, 23570, 23964, 24350, 24729, 25100, 25464, 25820, 26168, 26509, 26841, 27165, 27480, 27787, 28086, 28377, 28658, 28931, 29195, 29450, 29696, 29934, 30162, 30381, 30590, 30790, 30981, 31163, 31335, 31497, 31650, 31793, 31927, 32050, 32164, 32269, 32363, 32448, 32522, 32587, 32642, 32687, 32722, 32747, 32762, 32767, 32762, 32747, 32722, 32687, 32642, 32587, 32522, 32448, 32363, 32269, 32164, 32050, 31927, 31793, 31650, 31497, 31335, 31163, 30981, 30790, 30590, 30381, 30162, 29934, 29696, 29450, 29195, 28931, 28658, 28377, 28086, 27787, 27480, 27165, 26841, 26509, 26168, 25820, 25464, 25100, 24729, 24350, 23964, 23570, 23169, 22761, 22347, 21925, 21497, 21062, 20620, 20173, 19719, 19259, 18794, 18323, 17846, 17363, 16876, 16383, 15885, 15383, 14875, 14364, 13847, 13327, 12803, 12274, 11742, 11206, 10667, 10125, 9580, 9031, 8480, 7927, 7370, 6812, 6252, 5689, 5125, 4560, 3993, 3425, 2855, 2285, 1714, 1143, 571, 0, -571, -1143, -1714, -2285, -2855, -3425, -3993, -4560, -5125, -5689, -6252, -6812, -7370, -7927, -8480, -9031, -9580, -10125, -10667, -11206, -11742, -12274, -12803, -13327, -13847, -14364, -14875, -15383, -15885, -16383, -16876, -17363, -17846, -18323, -18794, -19259, -19719, -20173, -20620, -21062, -21497, -21925, -22347, -22761, -23169, -23570, -23964, -24350, -24729, -25100, -25464, -25820, -26168, -26509, -26841, -27165, -27480, -27787, -28086, -28377, -28658, -28931, -29195, -29450, -29696, -29934, -30162, -30381, -30590, -30790, -30981, -31163, -31335, -31497, -31650, -31793, -31927, -32050, -32164, -32269, -32363, -32448, -32522, -32587, -32642, -32687, -32722, -32747, -32762, -32767, -32762, -32747, -32722, -32687, -32642, -32587, -32522, -32448, -32363, -32269, -32164, -32050, -31927, -31793, -31650, -31497, -31335, -31163, -30981, -30790, -30590, -30381, -30162, -29934, -29696, -29450, -29195, -28931, -28658, -28377, -28086, -27787, -27480, -27165, -26841, -26509, -26168, -25820, -25464, -25100, -24729, -24350, -23964, -23570, -23169, -22761, -22347, -21925, -21497, -21062, -20620, -20173, -19719, -19259, -18794, -18323, -17846, -17363, -16876, -16383, -15885, -15383, -14875, -14364, -13847, -13327, -12803, -12274, -11742, -11206, -10667, -10125, -9580, -9031, -8480, -7927, -7370, -6812, -6252, -5689, -5125, -4560, -3993, -3425, -2855, -2285, -1714, -1143, -571 }; CREATE_ENVELOPE(sine) { - uint32_t i, sine_div, sine_mod, pos = 0, count = 0; + unsigned i; + uint32_t sine_div, sine_mod, pos = 0, count = 0; int32_t value = 0; const int16_t *const lut = (avctx->sine_lut ? avctx->sine_lut : sine_lut); sine_div = 360 / points; sine_mod = 360 % points; for (i = points; i > 0; i--) { value = lut[pos]; if (scale_type) value = -value; pos += sine_div; value = (((value * (int32_t) scale) + 16383) / 32767) + y_offset; count += sine_mod; if (count >= points) { count -= points; pos++; } *data++ = value; } } CREATE_ENVELOPE(cosine) { - uint32_t i, sine_div, sine_mod, count = 0; + unsigned i; + uint32_t sine_div, sine_mod, count = 0; int32_t pos = 90, value = 0; const int16_t *const lut = (avctx->sine_lut ? avctx->sine_lut : sine_lut); sine_div = 360 / points; sine_mod = 360 % points; for (i = points; i > 0; i--) { value = lut[pos]; if (scale_type) value = -value; if ((pos -= sine_div) < 0) pos += 360; value = (((value * (int32_t) scale) + 16383) / 32767) + y_offset; count += sine_mod; if (count >= points) { count -= points; pos--; if (pos < 0) pos += 360; } *data++ = value; } } CREATE_ENVELOPE(ramp) { - uint32_t i, start_scale = -scale, ramp_points, scale_div, scale_mod, scale_count = 0, value; + unsigned i; + uint32_t start_scale = -scale, ramp_points, scale_div, scale_mod, scale_count = 0, value; if (!(ramp_points = points >> 1)) ramp_points = 1; scale_div = scale / ramp_points; scale_mod = scale % ramp_points; for (i = points; i > 0; i--) { value = start_scale; start_scale += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; start_scale++; } if (scale_type) value = -value; value += y_offset; *data++ = value; } } CREATE_ENVELOPE(square) { unsigned i; uint32_t j, value; if (scale_type) scale = -scale; for (i = 2; i > 0; i--) { scale = -scale; value = (scale + y_offset); for (j = points >> 1; j > 0; j--) { *data++ = value; } } } CREATE_ENVELOPE(triangle) { - uint32_t i, value, pos = 0, down_pos, triangle_points, scale_div, scale_mod, scale_count = 0; + unsigned i; + uint32_t value, pos = 0, down_pos, triangle_points, scale_div, scale_mod, scale_count = 0; if (!(triangle_points = points >> 2)) triangle_points = 1; scale_div = scale / triangle_points; scale_mod = scale % triangle_points; down_pos = points - triangle_points; for (i = points; i > 0; i--) { value = pos; if (down_pos >= i) { if (down_pos == i) { scale_count += scale_mod; scale_div = -scale_div; } if (triangle_points >= i) { scale_count += scale_mod; scale_div = -scale_div; down_pos = 0; } pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos--; } } else { pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos++; } } if (scale_type) value = -value; value += y_offset; *data++ = value; } } CREATE_ENVELOPE(sawtooth) { - uint32_t i, value, pos = scale, down_pos, sawtooth_points, scale_div, scale_mod, scale_count = 0; + unsigned i; + uint32_t value, pos = scale, down_pos, sawtooth_points, scale_div, scale_mod, scale_count = 0; down_pos = points >> 1; if (!(sawtooth_points = points >> 2)) sawtooth_points = 1; scale_div = -(scale / sawtooth_points); scale_mod = scale % sawtooth_points; for (i = points; i > 0; i--) { value = pos; if (down_pos >= i) { if (down_pos == i) { scale_count += scale_mod; scale_div = -scale_div; } pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos++; } } else { pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos--; } } if (scale_type) value = -value; value += y_offset; *data++ = value; } } static const void *create_env_lut[] = { create_empty_envelope, create_sine_envelope, create_cosine_envelope, create_ramp_envelope, create_triangle_envelope, create_square_envelope, create_sawtooth_envelope }; int avseq_envelope_data_open(AVSequencerContext *avctx, AVSequencerEnvelope *envelope, uint32_t points, uint32_t type, uint32_t scale, uint32_t y_offset, uint32_t nodes) { uint32_t scale_type; - void (**create_env_func)(AVSequencerContext *avctx, int16_t *data, uint32_t points, uint32_t scale, uint32_t scale_type, uint32_t y_offset); + void (**create_env_func)(const AVSequencerContext *const avctx, + int16_t *data, + uint32_t points, + uint32_t scale, + uint32_t scale_type, + uint32_t y_offset); int16_t *data; if (!envelope) return AVERROR_INVALIDDATA; if (!points) points = 64; if (points >= 0x10000) return AVERROR_INVALIDDATA; data = envelope->data; if (!(data = av_realloc(data, (points * sizeof(int16_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(envelope, AV_LOG_ERROR, "Cannot allocate envelope points.\n"); return AVERROR(ENOMEM); } if (!type) { if (points > envelope->points) memset(data + envelope->points, 0, (points - envelope->points) * sizeof(int16_t)); if (nodes) { uint16_t *node; uint16_t old_nodes; if (!nodes) nodes = 12; if (nodes == 1) nodes++; if (nodes >= 0x10000) return AVERROR_INVALIDDATA; old_nodes = envelope->nodes; node = envelope->node_points; if (!(node = av_realloc(node, (nodes * sizeof(uint16_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_free(data); av_log(envelope, AV_LOG_ERROR, "Cannot allocate envelope node data.\n"); return AVERROR(ENOMEM); } envelope->node_points = node; envelope->nodes = nodes; if (nodes > old_nodes) { uint32_t node_div, node_mod, value, count, i; if (old_nodes) value = node[old_nodes - 1]; else value = 0; nodes -= old_nodes; count = 0; if (nodes > points) nodes = points; node += old_nodes; node_div = points / nodes; node_mod = points % nodes; for (i = nodes; i > 0; i--) { *node++ = value; value += node_div; count += node_mod; if (count >= nodes) { count -= nodes; value++; } } *--node = points - 1; } else { node[nodes - 1] = points - 1; } } } else { if (type > 7) type = 0; else type--; scale_type = scale & 0x80000000; scale &= 0x7FFFFFFF; if (scale > 0x7FFF) scale = 0x7FFF; create_env_func = (void *) &(create_env_lut); create_env_func[type](avctx, data, points, scale, scale_type, y_offset); if (nodes) { uint32_t node_div, node_mod, value = 0, count = 0, i; uint16_t *node; if (!nodes) nodes = 12; if (nodes == 1) nodes++; if (nodes >= 0x10000) return AVERROR_INVALIDDATA; node = envelope->node_points; if (!(node = av_realloc(node, (nodes * sizeof(uint16_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_free(data); av_log(envelope, AV_LOG_ERROR, "Cannot allocate envelope node data.\n"); return AVERROR(ENOMEM); } envelope->node_points = node; envelope->nodes = nodes; if (nodes > points) nodes = points; node_div = points / nodes; node_mod = points % nodes; for (i = nodes; i > 0; i--) { *node++ = value; value += node_div; count += node_mod; if (count >= nodes) { count -= nodes; value++; } } *--node = points - 1; } } envelope->data = data; envelope->points = points; return 0; } void avseq_envelope_data_close(AVSequencerEnvelope *envelope) { if (envelope) { av_freep(&envelope->node_points); av_freep(&envelope->data); envelope->nodes = 0; envelope->points = 0; envelope->sustain_start = 0; envelope->sustain_end = 0; envelope->loop_start = 0; envelope->loop_end = 0; } } AVSequencerEnvelope *avseq_envelope_get_address(AVSequencerModule *module, uint32_t envelope) { if (!(module && envelope)) return NULL; if (envelope > module->envelopes) return NULL; return module->envelope_list[--envelope]; } AVSequencerKeyboard *avseq_keyboard_create(void) { return av_mallocz(sizeof(AVSequencerKeyboard) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_keyboard_destroy(AVSequencerKeyboard *keyboard) { av_free(keyboard); } int avseq_keyboard_open(AVSequencerModule *module, AVSequencerKeyboard *keyboard) { AVSequencerKeyboard **keyboard_list; uint16_t keyboards; unsigned i; if (!module) return AVERROR_INVALIDDATA; keyboard_list = module->keyboard_list; keyboards = module->keyboards; if (!(keyboard && ++keyboards)) { return AVERROR_INVALIDDATA; } else if (!(keyboard_list = av_realloc(keyboard_list, (keyboards * sizeof(AVSequencerKeyboard *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate keyboard definition list storage container.\n"); return AVERROR(ENOMEM); } for (i = 0; i < 120; ++i) { keyboard->key[i].sample = 0; keyboard->key[i].octave = i / 12; keyboard->key[i].note = (i % 12) + 1; } keyboard_list[keyboards - 1] = keyboard; module->keyboard_list = keyboard_list; module->keyboards = keyboards; return 0; } void avseq_keyboard_close(AVSequencerModule *module, AVSequencerKeyboard *keyboard) { AVSequencerKeyboard **keyboard_list; uint16_t keyboards, i; if (!(module && keyboard)) return; keyboard_list = module->keyboard_list; keyboards = module->keyboards; for (i = 0; i < keyboards; ++i) { if (keyboard_list[i] == keyboard) break; } if (keyboards && (i != keyboards)) { AVSequencerKeyboard *last_keyboard = keyboard_list[--keyboards]; if (!keyboards) { av_freep(&module->keyboard_list); module->keyboards = 0; } else if (!(keyboard_list = av_realloc(keyboard_list, (keyboards * sizeof(AVSequencerKeyboard *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_keyboards = i + 1; keyboard_list = module->keyboard_list; if (copy_keyboards < keyboards) memmove(keyboard_list + i, keyboard_list + copy_keyboards, (keyboards - copy_keyboards) * sizeof(AVSequencerKeyboard *)); keyboard_list[keyboards - 1] = NULL; } else { const unsigned copy_keyboards = i + 1; if (copy_keyboards < keyboards) { memmove(keyboard_list + i, keyboard_list + copy_keyboards, (keyboards - copy_keyboards) * sizeof(AVSequencerKeyboard *)); keyboard_list[keyboards - 1] = last_keyboard; } module->keyboard_list = keyboard_list; module->keyboards = keyboards; } } } AVSequencerKeyboard *avseq_keyboard_get_address(AVSequencerModule *module, uint32_t keyboard) { if (!(module && keyboard)) return NULL; if (keyboard > module->keyboards) return NULL; return module->keyboard_list[--keyboard]; } static const char *arpeggio_name(void *p) { AVSequencerArpeggio *arpeggio = p; AVMetadataTag *tag = av_metadata_get(arpeggio->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Arpeggio"; } static const AVClass avseq_arpeggio_class = { "AVSequencer Arpeggio", arpeggio_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerArpeggio *avseq_arpeggio_create(void) { return av_mallocz(sizeof(AVSequencerArpeggio) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_arpeggio_destroy(AVSequencerArpeggio *arpeggio) { if (arpeggio) av_metadata_free(&arpeggio->metadata); av_free(arpeggio); } int avseq_arpeggio_open(AVSequencerModule *module, AVSequencerArpeggio *arpeggio, uint32_t entries) { AVSequencerArpeggio **arpeggio_list; uint16_t arpeggios; int res; if (!module) return AVERROR_INVALIDDATA; arpeggio_list = module->arpeggio_list; arpeggios = module->arpeggios; if (!(arpeggio && ++arpeggios)) { return AVERROR_INVALIDDATA; } else if (!(arpeggio_list = av_realloc(arpeggio_list, (arpeggios * sizeof(AVSequencerArpeggio *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate arpeggio structure storage container.\n"); return AVERROR(ENOMEM); } arpeggio->av_class = &avseq_arpeggio_class; if ((res = avseq_arpeggio_data_open(arpeggio, entries)) < 0) { av_free(arpeggio_list); return res; } arpeggio_list[arpeggios - 1] = arpeggio; module->arpeggio_list = arpeggio_list; module->arpeggios = arpeggios; return 0; } void avseq_arpeggio_close(AVSequencerModule *module, AVSequencerArpeggio *arpeggio) { AVSequencerArpeggio **arpeggio_list; uint16_t arpeggios, i; if (!(module && arpeggio)) return; arpeggio_list = module->arpeggio_list; arpeggios = module->arpeggios; for (i = 0; i < arpeggios; ++i) { if (arpeggio_list[i] == arpeggio) break; } if (arpeggios && (i != arpeggios)) { AVSequencerArpeggio *last_arpeggio = arpeggio_list[--arpeggios]; if (!arpeggios) { av_freep(&module->arpeggio_list); module->arpeggios = 0; } else if (!(arpeggio_list = av_realloc(arpeggio_list, (arpeggios * sizeof(AVSequencerEnvelope *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_arpeggios = i + 1; arpeggio_list = module->arpeggio_list; if (copy_arpeggios < arpeggios) memmove(arpeggio_list + i, arpeggio_list + copy_arpeggios, (arpeggios - copy_arpeggios) * sizeof(AVSequencerArpeggio *)); arpeggio_list[arpeggios - 1] = NULL; } else { const unsigned copy_arpeggios = i + 1; if (copy_arpeggios < arpeggios) { memmove(arpeggio_list + i, arpeggio_list + copy_arpeggios, (arpeggios - copy_arpeggios) * sizeof(AVSequencerArpeggio *)); arpeggio_list[arpeggios - 1] = last_arpeggio; } module->arpeggio_list = arpeggio_list; module->arpeggios = arpeggios; } } avseq_arpeggio_data_close(arpeggio); } int avseq_arpeggio_data_open(AVSequencerArpeggio *arpeggio, uint32_t entries) { AVSequencerArpeggioData *data; if (!arpeggio) return AVERROR_INVALIDDATA; data = arpeggio->data; if (!entries) entries = 3; if (entries >= 0x10000) { return AVERROR_INVALIDDATA; } else if (!(data = av_realloc(data, (entries * sizeof(AVSequencerArpeggioData)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(arpeggio, AV_LOG_ERROR, "Cannot allocate arpeggio structure data.\n"); return AVERROR(ENOMEM); } else if (entries > arpeggio->entries) { memset(data + arpeggio->entries, 0, (entries - arpeggio->entries) * sizeof(AVSequencerArpeggioData)); } else if (!arpeggio->data) { memset(data, 0, entries * sizeof(AVSequencerArpeggioData)); } arpeggio->data = data; arpeggio->entries = entries; return 0; } void avseq_arpeggio_data_close(AVSequencerArpeggio *arpeggio) { if (arpeggio) { av_freep(&arpeggio->data); arpeggio->entries = 0; arpeggio->sustain_start = 0; arpeggio->sustain_end = 0; arpeggio->loop_start = 0; arpeggio->loop_end = 0; } } AVSequencerArpeggio *avseq_arpeggio_get_address(AVSequencerModule *module, uint32_t arpeggio) { if (!(module && arpeggio)) return NULL; if (arpeggio > module->arpeggios) return NULL; return module->arpeggio_list[--arpeggio]; } diff --git a/libavsequencer/player.c b/libavsequencer/player.c index e419691..7205552 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -8387,2501 +8387,2537 @@ EXECUTE_SYNTH_CODE_INSTRUCTION(panleft) instruction_data = panning; panning -= instruction_data; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panrght) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_right; player_channel->pan_sl_right = instruction_data; if ((panning += instruction_data) < instruction_data) panning = 0xFFFF; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panspd) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pandpth) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_depth = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->pannolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->pannolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->pannolo_waveform)) player_channel->pannolo_pos = instruction_data % waveform->samples; else player_channel->pannolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pannolo) { const AVSequencerSynthWave *waveform; uint16_t pannolo_rate; int16_t pannolo_depth; instruction_data += player_channel->variable[src_var]; if (!(pannolo_rate = (instruction_data >> 8))) pannolo_rate = player_channel->pannolo_rate; player_channel->pannolo_rate = pannolo_rate; pannolo_depth = (instruction_data & 0xFF) << 2; if (!pannolo_depth) pannolo_depth = player_channel->pannolo_depth; player_channel->pannolo_depth = pannolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t pannolo_slide_value; waveform_pos = player_channel->pannolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) pannolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else pannolo_slide_value = waveform->data[waveform_pos]; pannolo_slide_value *= -pannolo_depth; pannolo_slide_value >>= 7 - 2; player_channel->pannolo_pos = (waveform_pos + pannolo_rate) % waveform->samples; se_pannolo_do(avctx, player_channel, pannolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panval) { int32_t pannolo_slide_value; instruction_data += player_channel->variable[src_var]; pannolo_slide_value = (int16_t) instruction_data; se_pannolo_do(avctx, player_channel, pannolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(nop) { return synth_code_line; } static void process_row(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { uint32_t current_tick; AVSequencerSong *song = avctx->player_song; uint16_t counted = 0; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; current_tick = player_host_channel->tempo_counter; current_tick++; if (current_tick >= ((uint32_t) player_host_channel->fine_pattern_delay + player_host_channel->tempo)) current_tick = 0; if (!(player_host_channel->tempo_counter = current_tick)) { const AVSequencerTrack *track; const AVSequencerOrderList *const order_list = song->order_list + channel; AVSequencerOrderData *order_data; const AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t pattern_delay, row, last_row, track_length; uint32_t ord = -1; if (player_channel->host_channel == channel) { const uint32_t slide_value = player_host_channel->arpeggio_freq; player_host_channel->arpeggio_freq = 0; player_channel->frequency += slide_value; } player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO); AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); player_host_channel->effect = NULL; player_host_channel->arpeggio_tick = 0; player_host_channel->note_delay = 0; player_host_channel->retrig_tick_count = 0; if ((pattern_delay = player_host_channel->pattern_delay) && (pattern_delay > player_host_channel->pattern_delay_count++)) return; player_host_channel->pattern_delay_count = 0; player_host_channel->pattern_delay = 0; row = player_host_channel->row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP; order_data = player_host_channel->order; track = player_host_channel->track; goto loop_to_row; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; order_data = player_host_channel->order; if ((player_host_channel->chg_pattern < song->tracks) && ((track = song->track_list[player_host_channel->chg_pattern]))) { if (!(avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN)) player_host_channel->track = track; goto loop_to_row; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) goto get_new_pattern; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) { if (!row--) goto get_new_pattern; } else if (++row >= player_host_channel->max_row) { get_new_pattern: order_data = player_host_channel->order; if (avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN) { track = player_host_channel->track; goto loop_to_row; } ord = -1; if (order_data) { while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; } } check_next_empty_order: do { ord++; if ((ord >= order_list->orders) || !(order_data = order_list->order_data[ord])) { song_end_found: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if ((order_list->rep_start >= order_list->orders) || !(order_data = order_list->order_data[order_list->rep_start])) { disable_channel: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; player_host_channel->tempo = 0; return; } if (order_data->flags & (AVSEQ_ORDER_DATA_FLAG_END_ORDER|AVSEQ_ORDER_DATA_FLAG_END_SONG)) goto disable_channel; row = 0; if (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT)) goto disable_channel; if ((track = order_data->track)) break; } if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_ORDER) goto song_end_found; if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_SONG) { if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) goto disable_channel; goto song_end_found; } } while (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT) || !(track = order_data->track)); player_host_channel->order = order_data; player_host_channel->track = track; if (player_host_channel->gosub_depth < order_data->played) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) player_host_channel->tempo = 0; } order_data->played++; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; loop_to_row: track_length = track->last_row; row = order_data->first_row; last_row = order_data->last_row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; row = player_host_channel->break_row; if (track_length < row) row = order_data->first_row; } if (track_length < row) goto check_next_empty_order; if (track_length < last_row) last_row = track_length; player_host_channel->max_row = last_row + 1; if ((pattern_delay = order_data->tempo)) player_host_channel->tempo = pattern_delay; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) row = last_row - row; } player_host_channel->row = row; if ((int) ((player_host_channel->track->data) + row)->note == AVSEQ_TRACK_DATA_NOTE_END) { if (++counted) goto get_new_pattern; goto disable_channel; } } } static const AVSequencerPlayerEffects fx_lut[128] = { {arpeggio, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {fine_tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {note_slide, NULL, check_note_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {fine_vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {do_key_off, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {hold_delay, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_fade, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_cut, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_delay, preset_note_delay, NULL, 0x00, 0x00, 0x0000}, {tremor, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_retrigger, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {multi_retrigger_note, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {extended_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {invert_loop, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {exec_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {stop_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {volume_slide_up, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {volume_slide_down, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_volume_slide_up, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {fine_volume_slide_down, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, 0x00, 0x01, 0x0000}, {set_track_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {track_volume_slide_up, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_volume_slide_down, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_volume_slide_up, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {fine_track_volume_slide_down, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {track_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {panning_slide_left, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {panning_slide_right, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_panning_slide_left, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {fine_panning_slide_right, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_track_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {track_panning_slide_left, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_panning_slide_right, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_panning_slide_left, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {fine_track_panning_slide_right, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {track_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {set_relative_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_break, NULL, NULL, 0x00, 0x02, 0x0000}, {position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {relative_position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {change_pattern, NULL, NULL, 0x00, 0x02, 0x0000}, {reverse_pattern_play, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {fine_pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_loop, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub_return, NULL, NULL, 0x00, 0x02, 0x0000}, {channel_sync, NULL, NULL, 0x00, 0x02, 0x0000}, {set_sub_slides, NULL, NULL, 0x00, 0x02, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {sample_offset_high, NULL, NULL, 0x00, 0x01, 0x0000}, {sample_offset_low, NULL, NULL, 0x00, 0x01, 0x0000}, {set_hold, NULL, NULL, 0x00, 0x01, 0x0000}, {set_decay, NULL, NULL, 0x00, 0x01, 0x0000}, {set_transpose, preset_set_transpose, NULL, 0x00, 0x01, 0x0000}, {instrument_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {instrument_change, NULL, NULL, 0x00, 0x01, 0x0000}, {synth_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_synth_value, NULL, NULL, 0x00, 0x01, 0x0000}, {envelope_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_envelope_value, NULL, NULL, 0x00, 0x01, 0x0000}, {nna_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {loop_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_speed, NULL, NULL, 0x00, 0x00, 0x0000}, {speed_slide_faster, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {speed_slide_slower, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_speed_slide_faster, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {fine_speed_slide_slower, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {speed_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {spenolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {spenolo, NULL, NULL, 0x00, 0x00, 0x0000}, {channel_ctrl, NULL, check_channel_control, 0x00, 0x00, 0x0000}, {set_global_volume, NULL, NULL, 0x00, 0x00, 0x0000}, {global_volume_slide_up, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_volume_slide_down, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_volume_slide_up, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {fine_global_volume_slide_down, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {global_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, 0x00, 0x00, 0x0000}, {set_global_panning, NULL, NULL, 0x00, 0x00, 0x0000}, {global_panning_slide_left, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_panning_slide_right, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_panning_slide_left, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {fine_global_panning_slide_right, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {global_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {global_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_pannolo, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {user_sync, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0000} }; static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerTrack *track; const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *track_data; uint32_t fx = -1; if (!(track = player_host_channel->track)) return; track_data = track->data + player_host_channel->row; if ((track_fx = player_host_channel->effect)) { while (++fx < track_data->effects) { if (track_fx == track_data->effects_data[fx]) break; } } else if (track_data->effects) { fx = 0; track_fx = track_data->effects_data[0]; } else { track_fx = NULL; } player_host_channel->effect = track_fx; if ((fx < track_data->effects) && track_data->effects_data[fx]) { do { const int fx_byte = track_fx->command & 0x7F; if (fx_byte == AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = track_fx->data; if (player_host_channel->tempo_counter < player_host_channel->exec_fx) break; } } while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))); if (player_host_channel->effect != track_fx) { player_host_channel->effect = track_fx; AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; - void (*pre_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); + void (*pre_fx_func)(const AVSequencerContext *const avctx, + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + uint16_t data_word); const int fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; if ((pre_fx_func = effects_lut->pre_pattern_func)) pre_fx_func(avctx, player_host_channel, player_channel, channel, track_fx->data); } } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; - void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); + void (*check_func)(const AVSequencerContext *const avctx, + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + uint16_t *const fx_byte, + uint16_t *const data_word, + uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; - void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); + void (*check_func)(const AVSequencerContext *const avctx, + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + uint16_t *const fx_byte, + uint16_t *const data_word, + uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= (player_host_channel->sample == player_channel->sample); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= (player_host_channel->instr_note == player_channel->instr_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= (player_host_channel->sample_note == player_channel->sample_note); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= (player_host_channel->instrument == player_channel->instrument); if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= (player_host_channel->sample == player_channel->sample); return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; if (nna_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; - const AVSequencerEnvelope * (**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); - const AVSequencerEnvelope * (**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); + const AVSequencerEnvelope *(**assign_envelope)(const AVSequencerContext *const avctx, + const AVSequencerInstrument *instrument, + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const AVSequencerEnvelope **envelope, + AVSequencerPlayerEnvelope **player_envelope); + const AVSequencerEnvelope *(**assign_auto_envelope)(const AVSequencerSample *sample, + AVSequencerPlayerChannel *const player_channel, + AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; player_channel->global_instr_volume = instrument->global_volume; player_channel->volume_swing = instrument->volume_swing; volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; player_channel->auto_pannolo_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; player_channel->auto_pannolo_depth = sample->pannolo_depth; player_channel->auto_pannolo_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; } player_channel->pitch_pan_separation = instrument->pitch_pan_separation; player_channel->pitch_pan_center = instrument->pitch_pan_center; player_channel->panning_swing = instrument->panning_swing; panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } player_channel->note_swing = instrument->note_swing; player_channel->pitch_swing = instrument->pitch_swing; } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; new_player_channel->auto_pannolo_sweep = player_channel->auto_pannolo_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; new_player_channel->auto_pannolo_depth = player_channel->auto_pannolo_depth; new_player_channel->auto_pannolo_rate = player_channel->auto_pannolo_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; if (player_channel->wait_count[synth_type]--) { exec_synth_done: if ((player_channel->synth_flags & bit_mask) && !(player_channel->kill_count[synth_type]--)) return 0; return 1; } player_channel->wait_count[synth_type] = 0; if ((synth_code_line >= synth->size) || ((int8_t) player_channel->wait_type[synth_type] < 0)) goto exec_synth_done; i = 4 - 1; do { int8_t wait_volume_type; if (((wait_volume_type = ~player_channel->wait_type[synth_type]) >= 0) && (wait_volume_type == i) && (player_channel->wait_line[synth_type] == synth_code_line)) player_channel->wait_type[synth_type] = 0; } while (i--); instruction = synth_code->instruction; dst_var = synth_code->src_dst_var; instruction_data = synth_code->data; if (!instruction && !dst_var && !instruction_data) goto exec_synth_done; src_var = dst_var >> 4; dst_var &= 0x0F; synth_code_line++; if (instruction < 0) { const AVSequencerPlayerEffects *effects_lut; - void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); + void (*check_func)(const AVSequencerContext *const avctx, + AVSequencerPlayerHostChannel *const player_host_channel, + AVSequencerPlayerChannel *const player_channel, + const uint16_t channel, + uint16_t *const fx_byte, + uint16_t *const data_word, + uint16_t *const flags); uint16_t fx_byte, data_word, flags; fx_byte = ~instruction; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = instruction_data + player_channel->variable[src_var]; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, player_channel->host_channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!effects_lut->pre_pattern_func) { instruction_data = player_host_channel->virtual_channel; player_host_channel->virtual_channel = channel; effects_lut->effect_func(avctx, player_host_channel, player_channel, player_channel->host_channel, fx_byte, data_word); player_host_channel->virtual_channel = instruction_data; } player_channel->entry_pos[synth_type] = synth_code_line; } else { - uint16_t (**fx_exec_func)(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint16_t virtual_channel, uint16_t synth_code_line, const int src_var, int dst_var, uint16_t instruction_data, const int synth_type); + uint16_t (**fx_exec_func)(const AVSequencerContext *const avctx, + AVSequencerPlayerChannel *const player_channel, + const uint16_t virtual_channel, + uint16_t synth_code_line, + const int src_var, + int dst_var, + uint16_t instruction_data, + const int synth_type); fx_exec_func = (avctx->synth_code_exec_lut ? avctx->synth_code_exec_lut : se_lut); player_channel->entry_pos[synth_type] = fx_exec_func[(uint8_t) instruction](avctx, player_channel, channel, synth_code_line, src_var, dst_var, instruction_data, synth_type); } } while (++synth_count); return 0; } static const int8_t empty_waveform[256]; int avseq_playback_handler(AVMixerData *mixer_data) { AVSequencerContext *const avctx = (AVSequencerContext *) mixer_data->opaque; const AVSequencerModule *const module = avctx->player_module; const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; AVSequencerPlayerHostChannel *player_host_channel = avctx->player_host_channel; AVSequencerPlayerChannel *player_channel = avctx->player_channel; const AVSequencerPlayerHook *player_hook; uint16_t channel, virtual_channel; if (!(module && song && player_globals && player_host_channel && player_channel)) return 0; channel = 0; do { if (mixer_data->mixctx->get_channel) mixer_data->mixctx->get_channel(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE) { if (!player_globals->trace_count--) player_globals->trace_count = 0; return 0; } player_hook = avctx->player_hook; if (player_hook && (player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->play_type & AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG) { uint32_t play_time_calc, play_time_advance, play_time_fraction; play_time_calc = ((uint64_t) player_globals->tempo * player_globals->relative_speed) >> 16; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_time_frac += play_time_fraction; play_time_advance += (player_globals->play_time_frac < play_time_fraction); player_globals->play_time += play_time_advance; play_time_calc = player_globals->tempo; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_tics_frac += play_time_fraction; play_time_advance += (player_globals->play_tics_frac < play_time_fraction); player_globals->play_tics += play_time_advance; } channel = 0; do { player_channel = avctx->player_channel + player_host_channel->virtual_channel; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE)) { const AVSequencerTrack *const old_track = player_host_channel->track; const AVSequencerTrackEffect const *old_effect = player_host_channel->effect; const uint32_t old_tempo_counter = player_host_channel->tempo_counter; const uint16_t old_row = player_host_channel->row; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE); player_host_channel->track = (const AVSequencerTrack *) player_host_channel->instrument; player_host_channel->effect = NULL; player_host_channel->row = (uint32_t) player_host_channel->sample; player_host_channel->instrument = NULL; player_host_channel->sample = NULL; get_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->tempo_counter = player_host_channel->note_delay; get_note(avctx, player_host_channel, player_channel, channel); run_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->track = old_track; player_host_channel->effect = old_effect; player_host_channel->tempo_counter = old_tempo_counter; player_host_channel->row = old_row; } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) { const uint16_t note = player_host_channel->instr_note; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT; if ((int8_t) note < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } } else { const AVSequencerInstrument *const instrument = player_host_channel->instrument; AVSequencerPlayerChannel *new_player_channel; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, note / 12, note % 12, channel))) player_channel = new_player_channel; player_channel->volume = player_host_channel->sample_note; player_channel->sub_volume = 0; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample = player_host_channel->sample; const uint32_t frequency = (uint32_t) player_host_channel->instrument; uint32_t i; uint16_t virtual_channel; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE; player_host_channel->dct = 0; player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; player_host_channel->finetune = sample->finetune; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *) &virtual_channel); sample = player_host_channel->sample; player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_host_channel->instrument = NULL; player_channel->sample = sample; player_channel->frequency = frequency; player_channel->volume = player_host_channel->instr_note; player_channel->sub_volume = 0; player_host_channel->instr_note = 0; init_new_instrument(avctx, player_host_channel, player_channel); i = -1; while (++i < module->instruments) { uint16_t smp = -1; if (!(instrument = module->instrument_list[i])) continue; while (++smp < instrument->samples) { if (!(sample = instrument->sample_list[smp])) continue; if (sample == player_channel->sample) { player_host_channel->instrument = instrument; goto instrument_found; } } } instrument_found: player_channel->instrument = player_host_channel->instrument; init_new_sample(avctx, player_host_channel, player_channel); } if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { do { process_row(avctx, player_host_channel, player_channel, channel); get_effects(avctx, player_host_channel, player_channel, channel); if (player_channel->host_channel == channel) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO)) { const int32_t slide_value = player_host_channel->vibrato_slide; player_host_channel->vibrato_slide = 0; player_channel->frequency -= slide_value; } if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO)) { int16_t slide_value = player_host_channel->tremolo_slide; player_host_channel->tremolo_slide = 0; if ((int16_t) (slide_value = (player_channel->volume - slide_value)) < 0) slide_value = 0; if (slide_value > 255) slide_value = 255; player_channel->volume = slide_value; } } } while (get_note(avctx, player_host_channel, player_channel, channel)); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { player_channel = avctx->player_channel + player_host_channel->virtual_channel; run_effects(avctx, player_host_channel, player_channel, channel); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); virtual_channel = 0; channel = 0; player_channel = avctx->player_channel; do { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { const AVSequencerSample *sample; AVSequencerPlayerEnvelope *player_envelope; uint32_t frequency, host_volume, virtual_volume; uint32_t auto_vibrato_depth, auto_vibrato_count; int32_t auto_vibrato_value; uint16_t flags, slide_envelope_value; int16_t panning, abs_panning, panning_envelope_value; player_host_channel = avctx->player_host_channel + player_channel->host_channel; player_envelope = &player_channel->vol_env; if (player_envelope->tempo) { const uint16_t volume = run_envelope(avctx, player_envelope, 1, -0x8000); if (!player_envelope->tempo) { if (!(volume >> 8)) goto turn_note_off; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } run_envelope(avctx, &player_channel->pan_env, 1, 0); slide_envelope_value = run_envelope(avctx, &player_channel->slide_env, 1, 0); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency += player_channel->slide_env_freq; if ((frequency = player_channel->frequency)) { if ((int16_t) slide_envelope_value < 0) { slide_envelope_value = -slide_envelope_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) frequency = linear_slide_down(avctx, player_channel, frequency, slide_envelope_value); else frequency = amiga_slide_down(player_channel, frequency, slide_envelope_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) { frequency = linear_slide_up(avctx, player_channel, frequency, slide_envelope_value); } else { frequency = amiga_slide_up(player_channel, frequency, slide_envelope_value); } player_channel->slide_env_freq += old_frequency - frequency; } } else { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_envelope_frequency, old_frequency; int16_t octave, note; const int16_t slide_note = (int16_t) slide_envelope_value >> 8; int32_t finetune = slide_envelope_value & 0xFF; octave = slide_note / 12; note = slide_note % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (finetune * (int32_t) next_frequency) >> 8; slide_envelope_frequency = player_channel->slide_env_freq; old_frequency = player_channel->frequency; slide_envelope_frequency += old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_envelope_frequency) >> (24 - octave); player_channel->slide_env_freq += old_frequency - frequency; } if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_FADING) { int32_t fade_out = (uint32_t) player_channel->fade_out_count; if ((fade_out -= (int32_t) player_channel->fade_out) <= 0) goto turn_note_off; player_channel->fade_out_count = fade_out; } auto_vibrato_value = run_envelope(avctx, &player_channel->auto_vib_env, player_channel->auto_vibrato_rate, 0); auto_vibrato_depth = player_channel->auto_vibrato_depth << 8; auto_vibrato_count = (uint32_t) player_channel->auto_vibrato_count + player_channel->auto_vibrato_sweep; if (auto_vibrato_count > auto_vibrato_depth) auto_vibrato_count = auto_vibrato_depth; player_channel->auto_vibrato_count = auto_vibrato_count; auto_vibrato_count >>= 8; if ((auto_vibrato_value *= (int32_t) -auto_vibrato_count)) { uint32_t old_frequency = player_channel->frequency; auto_vibrato_value >>= 7 - 2; player_channel->frequency -= player_channel->auto_vibrato_freq; if ((frequency = player_channel->frequency)) { if (auto_vibrato_value < 0) { auto_vibrato_value = -auto_vibrato_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) frequency = linear_slide_up(avctx, player_channel, frequency, auto_vibrato_value); else frequency = amiga_slide_up(player_channel, frequency, auto_vibrato_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) { frequency = linear_slide_down(avctx, player_channel, frequency, auto_vibrato_value); } else { frequency = amiga_slide_down(player_channel, frequency, auto_vibrato_value); } player_channel->auto_vibrato_freq -= old_frequency - frequency; } } if ((sample = player_channel->sample) && sample->synth) { if (!execute_synth(avctx, player_host_channel, player_channel, channel, 0)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 1)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 2)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 3)) goto turn_note_off; } if ((!player_channel->mixer.data || !player_channel->mixer.bits_per_sample) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { player_channel->mixer.pos = 0; player_channel->mixer.len = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.data = (int16_t *) &empty_waveform; player_channel->mixer.repeat_start = 0; player_channel->mixer.repeat_length = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.repeat_count = 0; player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = (sizeof (empty_waveform[0]) * 8); player_channel->mixer.flags = AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } frequency = player_channel->frequency; if (sample) { if (frequency < sample->rate_min) frequency = sample->rate_min; if (frequency > sample->rate_max) frequency = sample->rate_max; } if (!(player_channel->frequency = frequency)) { turn_note_off: player_channel->mixer.flags = 0; goto not_calculate_no_playing; } if (!(player_channel->mixer.rate = ((uint64_t) frequency * player_globals->relative_pitch) >> 16)) goto turn_note_off; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_GLOBAL_NEW_ONLY)) { player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; } host_volume = player_channel->volume; player_host_channel->virtual_channels++; virtual_channel++; if (!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) && (player_host_channel->virtual_channel == channel) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC) && (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_ON))) host_volume = 0; host_volume *= (uint16_t) player_host_channel->track_volume * (uint16_t) player_channel->instr_volume; virtual_volume = (((uint16_t) player_channel->vol_env.value >> 8) * (uint16_t) player_channel->global_volume) * (uint16_t) player_channel->fade_out_count; player_channel->mixer.volume = player_channel->final_volume = ((uint64_t) host_volume * virtual_volume) / UINT64_C(70660093200890625); /* / (255ULL*255ULL*255ULL*255ULL*65535ULL*255ULL) */ flags = 0; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND; player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning = (uint8_t) player_channel->panning; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) { panning = (uint8_t) player_host_channel->track_panning; flags = 0; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN)) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; } player_channel->flags |= flags; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) player_channel->mixer.flags |= flags; if (panning == 255) panning++; panning_envelope_value = panning; if ((int16_t) (panning = (128 - panning)) < 0) panning = -panning; abs_panning = 128 - panning; panning = player_channel->pan_env.value >> 8; if (panning == 127) panning++; panning = 128 - (((panning * abs_panning) >> 7) + panning_envelope_value); abs_panning = (uint8_t) player_host_channel->channel_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning_envelope_value = abs_panning = ((panning * abs_panning) >> 7) + 128; if (panning_envelope_value > 255) panning_envelope_value = 255; player_channel->final_panning = panning_envelope_value; panning = 128; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_GLOBAL_SUR_PAN) player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning -= abs_panning; abs_panning = (uint8_t) player_channel->global_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning = ((panning * abs_panning) >> 7) + 128; if (panning == 256) panning--; } player_channel->mixer.panning = panning; if (mixer_data->mixctx->set_channel_volume_panning_pitch)
BastyCDGS/ffmpeg-soc
695bfb12a9631eaf1b36e663643295aa8ea82eb1
Reverted correct rounding changes due to signed values which need more special handling of rounding in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 6fcaaf5..75ff22e 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1036,2941 +1036,2931 @@ static void get_backwards_next_sample_16_to_8(const AV_HQMixerData *const mixer_ const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = volume_lut[(uint16_t) sample[offset - 1] >> 8]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32_to_8(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = volume_lut[(uint32_t) sample[offset + 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32_to_8(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = volume_lut[(uint32_t) sample[offset - 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x_to_8(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x_to_8(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } - smp = (((int64_t) sample[offset + 1] * mult_volume) + (div_volume >> 1)) / div_volume; + smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) get_backwards_next_sample_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } - smp = (((int64_t) sample[offset - 1] * mult_volume) + (div_volume >> 1)) / div_volume; + smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static inline void mulu_128(uint64_t *const result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; const uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; const uint64_t x3 = (uint64_t) a_lo * b_lo; uint64_t x0 = (uint64_t) a_hi * b_hi; x2 += x3 >> 32; x2 += x1; x0 += (x2 < x1) ? UINT64_C(0x100000000) : 0; result[0] = x0 + (x2 >> 32); result[1] = (x2 << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void neg_128(uint64_t *const result) { result[1] = ~result[1]; result[0] = ~result[0]; result[0] += (++result[1] ? 0 : 1); } static inline void muls_128(int64_t *const result, const int64_t a, const int64_t b) { const int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b); if (sign) neg_128(result); } static inline uint64_t divu_128(const uint64_t *const a, const uint64_t b) { uint64_t a_hi = a[0]; uint64_t a_lo = a[1]; uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t *const a, const int64_t b) { const int sign = (a[0] ^ b) < 0; int64_t result; if (a[0] < 0) neg_128(a); result = divu_128(a, b < 0 ? -b : b); if (sign) result = -result; return result; } static inline void add_128(int64_t *const a, const int64_t b) { a[1] += b; a[0] += ((uint64_t) a[1] < (uint64_t) b); } static void get_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int64_t tmp_128[2]; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } muls_128(tmp_128, sample[offset + 1], mult_volume); - add_128(tmp_128, div_volume >> 1); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int64_t tmp_128[2]; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } muls_128(tmp_128, sample[offset - 1], mult_volume); - add_128(tmp_128, div_volume >> 1); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); - add_128(tmp_128, div_volume >> 1); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); - add_128(tmp_128, div_volume >> 1); smp = divs_128(tmp_128, div_volume); if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *const sample = (const int8_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; - return (((int64_t) sample[offset] * mult_volume) + (div_volume >> 1)) / div_volume; + return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int64_t tmp_128[2]; muls_128(tmp_128, sample[offset], mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } - return (((int64_t) sample[offset] * mult_volume) + (div_volume >> 1)) / div_volume; + return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } - return (((int64_t) sample[offset] * mult_volume) + (div_volume >> 1)) / div_volume; + return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } muls_128(tmp_128, sample[offset], mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int64_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; int64_t tmp_128[2]; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } muls_128(tmp_128, smp_data, mult_volume); - add_128(tmp_128, div_volume >> 1); return divs_128(tmp_128, div_volume); } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += ((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31; *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; @@ -6369,1025 +6359,1025 @@ static const int32_t damp_factor_lut[] = { 23247427, 23231750, 23216083, 23200427, 23184782, 23169147, 23153523, 23137909, 23122306, 23106713, 23091131, 23075559, 23059998, 23044447, 23028907, 23013377, 22997858, 22982349, 22966851, 22951363, 22935886, 22920419, 22904962, 22889516, 22874080, 22858655, 22843240, 22827836, 22812441, 22797058, 22781684, 22766321, 22750969, 22735626, 22720294, 22704973, 22689661, 22674361, 22659070, 22643790, 22628520, 22613260, 22598010, 22582771, 22567542, 22552324, 22537115, 22521917, 22506730, 22491552, 22476385, 22461227, 22446081, 22430944, 22415817, 22400701, 22385595, 22370499, 22355413, 22340338, 22325272, 22310217, 22295172, 22280137, 22265112, 22250098, 22235093, 22220099, 22205114, 22190140, 22175176, 22160222, 22145278, 22130344, 22115421, 22100507, 22085603, 22070710, 22055826, 22040953, 22026089, 22011236, 21996392, 21981559, 21966735, 21951922, 21937118, 21922325, 21907541, 21892768, 21878004, 21863251, 21848507, 21833773, 21819050, 21804336, 21789632, 21774938, 21760254, 21745579, 21730915, 21716261, 21701616, 21686982, 21672357, 21657742, 21643137, 21628542, 21613956, 21599381, 21584815, 21570259, 21555713, 21541177, 21526650, 21512134, 21497627, 21483130, 21468642, 21454165, 21439697, 21425239, 21410791, 21396352, 21381923, 21367504, 21353095, 21338695, 21324305, 21309925, 21295555, 21281194, 21266843, 21252501, 21238169, 21223847, 21209535, 21195232, 21180939, 21166655, 21152381, 21138117, 21123862, 21109617, 21095382, 21081156, 21066940, 21052733, 21038536, 21024349, 21010171, 20996002, 20981843, 20967694, 20953554, 20939424, 20925304, 20911192, 20897091, 20882999, 20868916, 20854843, 20840779, 20826725, 20812680, 20798645, 20784620, 20770603, 20756596, 20742599, 20728611, 20714633, 20700664, 20686704, 20672754, 20658813, 20644881, 20630959, 20617047, 20603143, 20589250, 20575365, 20561490, 20547624, 20533768, 20519920, 20506083, 20492254, 20478435, 20464625, 20450825, 20437034, 20423252, 20409479, 20395716, 20381962, 20368217, 20354482, 20340755, 20327039, 20313331, 20299632, 20285943, 20272263, 20258592, 20244931, 20231279, 20217635, 20204001, 20190377, 20176761, 20163155, 20149558, 20135970, 20122391, 20108821, 20095261, 20081709, 20068167, 20054634, 20041110, 20027595, 20014089, 20000592, 19987105, 19973626, 19960157, 19946697, 19933246, 19919803, 19906370, 19892946, 19879531, 19866125, 19852729, 19839341, 19825962, 19812592, 19799231, 19785880, 19772537, 19759203, 19745878, 19732562, 19719256, 19705958, 19692669, 19679389, 19666118, 19652856, 19639603, 19626359, 19613124, 19599897, 19586680, 19573472, 19560272, 19547081, 19533900, 19520727, 19507563, 19494408, 19481262, 19468124, 19454996, 19441876, 19428765, 19415663, 19402570, 19389486, 19376411, 19363344, 19350286, 19337237, 19324197, 19311165, 19298143, 19285129, 19272124, 19259128, 19246140, 19233161, 19220191, 19207230, 19194277, 19181334, 19168398, 19155472, 19142554, 19129646, 19116745, 19103854, 19090971, 19078097, 19065231, 19052375, 19039526, 19026687, 19013856, 19001034, 18988221, 18975416, 18962619, 18949832, 18937053, 18924283, 18911521, 18898768, 18886023, 18873287, 18860560, 18847841, 18835131, 18822429, 18809736, 18797052, 18784376, 18771708, 18759049, 18746399, 18733757, 18721124, 18708499, 18695883, 18683275, 18670676, 18658086, 18645503, 18632930, 18620364, 18607807, 18595259, 18582719, 18570188, 18557665, 18545150, 18532644, 18520147, 18507658, 18495177, 18482704, 18470240, 18457785, 18445338, 18432899, 18420469, 18408047, 18395633, 18383228, 18370831, 18358442, 18346062, 18333690, 18321327, 18308972, 18296625, 18284286, 18271956, 18259634, 18247321, 18235016, 18222719, 18210430, 18198150, 18185878, 18173614, 18161358, 18149111, 18136872, 18124641, 18112419, 18100205, 18087999, 18075801, 18063611, 18051430, 18039257, 18027092, 18014935, 18002787, 17990646, 17978514, 17966390, 17954274, 17942167, 17930067, 17917976, 17905893, 17893818, 17881751, 17869692, 17857642, 17845599, 17833565, 17821539, 17809521, 17797511, 17785509, 17773515, 17761529, 17749552, 17737582, 17725621, 17713667, 17701722, 17689785, 17677855, 17665934, 17654021, 17642116, 17630219, 17618330, 17606449, 17594576, 17582711, 17570854, 17559005, 17547164, 17535330, 17523505, 17511688, 17499879, 17488078, 17476285, 17464499, 17452722, 17440953, 17429191, 17417438, 17405692, 17393954, 17382225, 17370503, 17358789, 17347083, 17335385, 17323695, 17312012, 17300338, 17288671, 17277012, 17265361, 17253718, 17242083, 17230456, 17218836, 17207225, 17195621, 17184025, 17172437, 17160856, 17149284, 17137719, 17126162, 17114613, 17103071, 17091538, 17080012, 17068494, 17056984, 17045481, 17033986, 17022499, 17011020, 16999549, 16988085, 16976629, 16965181, 16953740, 16942307, 16930882, 16919464, 16908055, 16896653, 16885258, 16873871, 16862492, 16851121, 16839757, 16828401, 16817053, 16805712, 16794379, 16783054, 16771736, 16760426, 16749123, 16737828, 16726541, 16715261, 16703989, 16692725, 16681468, 16670219, 16658977, 16647743, 16636516, 16625297, 16614086, 16602882, 16591686, 16580497, 16569316, 16558142, 16546976, 16535818, 16524667, 16513523, 16502387, 16491258, 16480137, 16469024, 16457918, 16446819, 16435728, 16424645, 16413569, 16402500, 16391439, 16380385, 16369339, 16358300, 16347269, 16336245, 16325228, 16314219, 16303218, 16292224, 16281237, 16270257, 16259285, 16248321, 16237364, 16226414, 16215471, 16204536, 16193609, 16182688, 16171776, 16160870, 16149972, 16139081, 16128197, 16117321, 16106452, 16095591, 16084737, 16073890, 16063050, 16052218, 16041393, 16030575, 16019765, 16008962, 15998166, 15987378, 15976596, 15965823, 15955056, 15944296, 15933544, 15922799, 15912062, 15901331, 15890608, 15879892, 15869183, 15858482, 15847788, 15837101, 15826421, 15815748, 15805082, 15794424, 15783773, 15773129, 15762492, 15751863, 15741240, 15730625, 15720017, 15709416, 15698822, 15688236, 15677656, 15667084, 15656519, 15645961, 15635410, 15624866, 15614329, 15603799, 15593277, 15582761, 15572253, 15561752, 15551258, 15540771, 15530290, 15519818, 15509352, 15498893, 15488441, 15477996, 15467558, 15457128, 15446704, 15436288, 15425878, 15415475, 15405080, 15394691, 15384310, 15373935, 15363568, 15353207, 15342854, 15332507, 15322167, 15311835, 15301509, 15291190, 15280879, 15270574, 15260276, 15249985, 15239701, 15229424, 15219154, 15208891, 15198635, 15188385, 15178143, 15167908, 15157679, 15147457, 15137242, 15127035, 15116833, 15106639, 15096452, 15086272, 15076098, 15065931, 15055772, 15045619, 15035472, 15025333, 15015201, 15005075, 14994956, 14984844, 14974739, 14964641, 14954549, 14944465, 14934387, 14924316, 14914251, 14904194, 14894143, 14884099, 14874062, 14864031, 14854008, 14843991, 14833981, 14823977, 14813980, 14803991, 14794007, 14784031, 14774061, 14764098, 14754142, 14744192, 14734249, 14724313, 14714384, 14704461, 14694545, 14684636, 14674733, 14664837, 14654947, 14645065, 14635189, 14625319, 14615457, 14605601, 14595751, 14585909, 14576072, 14566243, 14556420, 14546604, 14536794, 14526991, 14517195, 14507405, 14497622, 14487845, 14478075, 14468312, 14458555, 14448805, 14439061, 14429324, 14419593, 14409870, 14400152, 14390441, 14380737, 14371039, 14361348, 14351663, 14341985, 14332313, 14322648, 14312990, 14303338, 14293692, 14284053, 14274420, 14264794, 14255175, 14245562, 14235955, 14226355, 14216761, 14207174, 14197593, 14188019, 14178451, 14168890, 14159335, 14149787, 14140245, 14130709, 14121180, 14111657, 14102141, 14092631, 14083127, 14073630, 14064140, 14054655, 14045178, 14035706, 14026241, 14016782, 14007330, 13997884, 13988444, 13979011, 13969584, 13960164, 13950750, 13941342, 13931940, 13922545, 13913157, 13903774, 13894398, 13885028, 13875665, 13866308, 13856957, 13847612, 13838274, 13828942, 13819616, 13810297, 13800984, 13791677, 13782377, 13773082, 13763794, 13754513, 13745237, 13735968, 13726705, 13717448, 13708198, 13698954, 13689716, 13680484, 13671258, 13662039, 13652826, 13643619, 13634418, 13625224, 13616035, 13606853, 13597677, 13588508, 13579344, 13570187, 13561036, 13551891, 13542752, 13533619, 13524493, 13515372, 13506258, 13497150, 13488048, 13478952, 13469863, 13460779, 13451702, 13442631, 13433566, 13424506, 13415454, 13406407, 13397366, 13388331, 13379303, 13370280, 13361264, 13352254, 13343250, 13334251, 13325259, 13316273, 13307293, 13298320, 13289352, 13280390, 13271434, 13262485, 13253541, 13244603, 13235672, 13226746, 13217827, 13208913, 13200005, 13191104, 13182208, 13173319, 13164435, 13155558, 13146686, 13137821, 13128961, 13120107, 13111260, 13102418, 13093582, 13084753, 13075929, 13067111, 13058299, 13049493, 13040693, 13031899, 13023111, 13014329, 13005552, 12996782, 12988017, 12979259, 12970506, 12961759, 12953018, 12944284, 12935554, 12926831, 12918114, 12909402, 12900697, 12891997, 12883303, 12874615, 12865933, 12857257, 12848587, 12839922, 12831263, 12822611, 12813964, 12805322, 12796687, 12788057, 12779434, 12770816, 12762204, 12753597, 12744997, 12736402, 12727813, 12719230, 12710653, 12702081, 12693516, 12684956, 12676401, 12667853, 12659310, 12650773, 12642242, 12633717, 12625197, 12616683, 12608175, 12599673, 12591176, 12582685, 12574200, 12565720, 12557247, 12548779, 12540316, 12531859, 12523409, 12514963, 12506524, 12498090, 12489662, 12481239, 12472822, 12464411, 12456006, 12447606, 12439212, 12430823, 12422440, 12414063, 12405692, 12397326, 12388966, 12380611, 12372262, 12363919, 12355581, 12347249, 12338922, 12330602, 12322286, 12313977, 12305673, 12297374, 12289081, 12280794, 12272513, 12264236, 12255966, 12247701, 12239442, 12231188, 12222940, 12214697, 12206460, 12198229, 12190003, 12181782, 12173567, 12165358, 12157154, 12148956, 12140763, 12132576, 12124394, 12116218, 12108047, 12099882, 12091723, 12083568, 12075420, 12067277, 12059139, 12051007, 12042880, 12034759, 12026643, 12018533, 12010428, 12002329, 11994235, 11986146, 11978063, 11969986, 11961914, 11953847, 11945786, 11937730, 11929680, 11921635, 11913596, 11905562, 11897533, 11889510, 11881492, 11873480, 11865473, 11857471, 11849475, 11841484, 11833499, 11825519, 11817544, 11809575, 11801611, 11793653, 11785699, 11777752, 11769809, 11761872, 11753940, 11746014, 11738093, 11730177, 11722267, 11714362, 11706462, 11698568, 11690679, 11682795, 11674917, 11667044, 11659176, 11651314, 11643456, 11635605, 11627758, 11619917, 11612081, 11604250, 11596425, 11588605, 11580790, 11572980, 11565176, 11557377, 11549583, 11541794, 11534011, 11526233, 11518460, 11510693, 11502930, 11495173, 11487421, 11479675, 11471933, 11464197, 11456466, 11448740, 11441020, 11433304, 11425594, 11417889, 11410190, 11402495, 11394806, 11387121, 11379442, 11371769, 11364100, 11356437, 11348778, 11341125, 11333477, 11325834, 11318197, 11310564, 11302937, 11295315, 11287697, 11280086, 11272479, 11264877, 11257280, 11249689, 11242103, 11234521, 11226945, 11219374, 11211809, 11204248, 11196692, 11189142, 11181596, 11174056, 11166520, 11158990, 11151465, 11143945, 11136430, 11128920, 11121415, 11113915, 11106420, 11098931, 11091446, 11083966, 11076492, 11069022, 11061558, 11054098, 11046644, 11039195, 11031750, 11024311, 11016877, 11009447, 11002023, 10994604, 10987189, 10979780, 10972376, 10964976, 10957582, 10950193, 10942808, 10935429, 10928055, 10920685, 10913321, 10905961, 10898607, 10891257, 10883913, 10876573, 10869238, 10861909, 10854584, 10847264, 10839949, 10832639, 10825334, 10818034, 10810738, 10803448, 10796163, 10788882, 10781607, 10774336, 10767070, 10759809, 10752553, 10745302, 10738056, 10730815, 10723579, 10716347, 10709120, 10701899, 10694682, 10687470, 10680262, 10673060, 10665863, 10658670, 10651482, 10644299, 10637121, 10629948, 10622780, 10615616, 10608457, 10601303, 10594154, 10587010, 10579871, 10572736, 10565606, 10558481, 10551361, 10544246, 10537135, 10530029, 10522928, 10515832, 10508741, 10501654, 10494572, 10487495, 10480423, 10473355, 10466292, 10459234, 10452181, 10445133, 10438089, 10431050, 10424015, 10416986, 10409961, 10402941, 10395926, 10388915, 10381909, 10374908, 10367912, 10360920, 10353933, 10346951, 10339973, 10333001, 10326032, 10319069, 10312110, 10305156, 10298207, 10291262, 10284322, 10277387, 10270456, 10263530, 10256609, 10249692, 10242780, 10235873, 10228970, 10222072, 10215179, 10208290, 10201406, 10194527, 10187652, 10180782, 10173917, 10167056, 10160199, 10153348, 10146501, 10139659, 10132821, 10125988, 10119159, 10112335, 10105516, 10098701, 10091891, 10085085, 10078284, 10071488, 10064696, 10057909, 10051126, 10044348, 10037575, 10030806, 10024042, 10017282, 10010527, 10003776, 9997030, 9990288, 9983551, 9976819, 9970091, 9963367, 9956648, 9949934, 9943224, 9936519, 9929818, 9923122, 9916430, 9909743, 9903060, 9896382, 9889708, 9883039, 9876374, 9869714, 9863059, 9856407, 9849761, 9843118, 9836481, 9829847, 9823218, 9816594, 9809974, 9803359, 9796748, 9790141, 9783539, 9776941, 9770348, 9763760, 9757175, 9750596, 9744020, 9737449, 9730883, 9724321, 9717763, 9711210, 9704661, 9698116, 9691576, 9685041, 9678510, 9671983, 9665460, 9658942, 9652429, 9645920, 9639415, 9632914, 9626418, 9619927, 9613440, 9606957, 9600478, 9594004, 9587534, 9581069, 9574608, 9568151, 9561699, 9555251, 9548807, 9542368, 9535933, 9529502, 9523076, 9516654, 9510236, 9503823, 9497414, 9491009, 9484609, 9478213, 9471821, 9465434, 9459051, 9452672, 9446297, 9439927, 9433561, 9427200, 9420842, 9414489, 9408141, 9401796, 9395456, 9389120, 9382788, 9376461, 9370138, 9363819, 9357505, 9351194, 9344888, 9338586, 9332289, 9325996, 9319706, 9313422, 9307141, 9300865, 9294593, 9288325, 9282061, 9275802, 9269546, 9263295, 9257049, 9250806, 9244568, 9238334, 9232104, 9225878, 9219656, 9213439, 9207226, 9201017, 9194812, 9188612, 9182415, 9176223, 9170035, 9163851, 9157671, 9151496, 9145324, 9139157, 9132994, 9126835, 9120680, 9114530, 9108383, 9102241, 9096103, 9089969, 9083839, 9077713, 9071591, 9065474, 9059361, 9053251, 9047146, 9041045, 9034948, 9028856, 9022767, 9016682, 9010602, 9004525, 8998453, 8992385, 8986321, 8980261, 8974205, 8968153, 8962105, 8956062, 8950022, 8943987, 8937955, 8931928, 8925904, 8919885, 8913870, 8907859, 8901852, 8895849, 8889850, 8883855, 8877864, 8871877, 8865894, 8859915, 8853941, 8847970, 8842003, 8836041, 8830082, 8824127, 8818177, 8812230, 8806288, 8800349, 8794414, 8788484, 8782557, 8776635, 8770716, 8764801, 8758891, 8752984, 8747081, 8741183, 8735288, 8729397, 8723511, 8717628, 8711749, 8705874, 8700003, 8694136, 8688274, 8682415, 8676559, 8670708, 8664861, 8659018, 8653179, 8647343, 8641512, 8635684, 8629861, 8624041, 8618226, 8612414, 8606606, 8600802, 8595002, 8589206, 8583414, 8577625, 8571841, 8566061, 8560284, 8554511, 8548742, 8542978, 8537217, 8531459, 8525706, 8519957, 8514211, 8508470, 8502732, 8496998, 8491268, 8485542, 8479820, 8474101, 8468387, 8462676, 8456969, 8451266, 8445567, 8439871, 8434180, 8428492, 8422808, 8417128, 8411452, 8405780, 8400111, 8394447, 8388786, 8383129, 8377476, 8371826, 8366181, 8360539, 8354901, 8349267, 8343636, 8338010, 8332387, 8326768, 8321153, 8315541, 8309933, 8304330, 8298730, 8293133, 8287541, 8281952, 8276367, 8270786, 8265208, 8259634, 8254065, 8248498, 8242936, 8237377, 8231822, 8226271, 8220724, 8215180, 8209640, 8204104, 8198571, 8193042, 8187517, 8181996, 8176478, 8170965, 8165454, 8159948, 8154445, 8148946, 8143451, 8137959, 8132471, 8126987, 8121507, 8116030, 8110557, 8105087, 8099622, 8094160, 8088701, 8083247, 8077796, 8072348, 8066905, 8061465, 8056028, 8050596, 8045167, 8039741, 8034320, 8028902, 8023487, 8018077, 8012670, 8007266, 8001866, 7996470, 7991078, 7985689, 7980304, 7974922, 7969544, 7964170, 7958799, 7953432, 7948069, 7942709, 7937353, 7932000, 7926651, 7921306, 7915964, 7910626, 7905291, 7899960, 7894633, 7889309, 7883989, 7878672, 7873359, 7868049, 7862744, 7857441, 7852143, 7846847, 7841556, 7836268, 7830983, 7825702, 7820425, 7815151, 7809881, 7804614, 7799351, 7794092, 7788836, 7783583, 7778334, 7773089, 7767847, 7762609, 7757374, 7752143, 7746915, 7741691, 7736470, 7731253, 7726039, 7720829, 7715623, 7710420, 7705220, 7700024, 7694831, 7689642, 7684457, 7679275, 7674096, 7668921, 7663749, 7658581, 7653417, 7648256, 7643098, 7637944, 7632793, 7627646, 7622502, 7617362, 7612225, 7607092, 7601962, 7596835, 7591712, 7586593, 7581477, 7576364, 7571255, 7566149, 7561047, 7555948, 7550852, 7545760, 7540672, 7535587, 7530505, 7525427, 7520352, 7515281, 7510213, 7505148, 7500087, 7495029, 7489975, 7484924, 7479876, 7474832, 7469792, 7464754, 7459720, 7454690, 7449663, 7444639, 7439619, 7434602, 7429588, 7424578, 7419571, 7414568, 7409568, 7404571, 7399577, 7394588, 7389601, 7384618, 7379638, 7374661, 7369688, 7364718, 7359752, 7354789, 7349829, 7344873, 7339920, 7334970, 7330023, 7325080, 7320141, 7315204, 7310271, 7305341, 7300415, 7295492, 7290572, 7285656, 7280743, 7275833, 7270926, 7266023, 7261123, 7256226, 7251333, 7246443, 7241556, 7236673, 7231793, 7226916, 7222043, 7217172, 7212305, 7207442, 7202581, 7197724, 7192870, 7188020, 7183173, 7178329, 7173488, 7168650, 7163816, 7158985, 7154157, 7149333, 7144512, 7139694, 7134879, 7130068, 7125259, 7120454, 7115653, 7110854, 7106059, 7101267, 7096478, 7091692, 7086910, 7082131, 7077355, 7072582, 7067813, 7063047, 7058284, 7053524, 7048767, 7044014, 7039264, 7034517, 7029773, 7025032, 7020295, 7015561, 7010830, 7006102, 7001377, 6996656, 6991938, 6987223, 6982511, 6977802, 6973096, 6968394, 6963695, 6958999, 6954306, 6949616, 6944930, 6940246, 6935566, 6930889, 6926215, 6921545, 6916877, 6912212, 6907551, 6902893, 6898238, 6893586, 6888937, 6884292, 6879649, 6875010, 6870374, 6865741, 6861111, 6856484, 6851860, 6847239, 6842622, 6838008, 6833396, 6828788, 6824183, 6819581, 6814982, 6810387, 6805794, 6801204, 6796618, 6792035, 6787454, 6782877, 6778303, 6773732, 6769164, 6764599, 6760038, 6755479, 6750923, 6746371, 6741821, 6737275, 6732732, 6728191, 6723654, 6719120, 6714589, 6710061, 6705536, 6701014, 6696495, 6691979, 6687466, 6682957, 6678450, 6673946, 6669446, 6664948, 6660453, 6655962, 6651473, 6646988, 6642506, 6638026, 6633550, 6629076, 6624606, 6620139, 6615674, 6611213, 6606755, 6602299, 6597847, 6593398, 6588951, 6584508, 6580068, 6575630, 6571196, 6566765, 6562336, 6557911, 6553489, 6549069, 6544653, 6540239, 6535829, 6531421, 6527017, 6522615, 6518217, 6513821, 6509428, 6505039, 6500652, 6496268, 6491888, 6487510, 6483135, 6478763, 6474394, 6470028, 6465665, 6461304, 6456947, 6452593, 6448242, 6443893, 6439548, 6435205, 6430865, 6426529, 6422195, 6417864, 6413536, 6409211, 6404889, 6400570, 6396254, 6391940, 6387630, 6383322, 6379018, 6374716, 6370417, 6366121, 6361828, 6357538, 6353251, 6348966, 6344685, 6340406, 6336130, 6331858, 6327588, 6323321, 6319056, 6314795, 6310537, 6306281, 6302028, 6297779, 6293532, 6289288, 6285046, 6280808, 6276572, 6272340, 6268110, 6263883, 6259659, 6255438, 6251219, 6247004, 6242791, 6238581, 6234374, 6230170, 6225969, 6221770, 6217574, 6213381, 6209191, 6205004, 6200820, 6196638, 6192459, 6188284, 6184110, 6179940, 6175773, 6171608, 6167446, 6163287, 6159131, 6154977, 6150827, 6146679, 6142534, 6138391, 6134252, 6130115, 6125981, 6121850, 6117722, 6113596, 6109474, 6105354, 6101237, 6097122, 6093010, 6088902, 6084795, 6080692, 6076592, 6072494, 6068399, 6064306, 6060217, 6056130, 6052046, 6047965, 6043886, 6039811, 6035738, 6031667, 6027600, 6023535, 6019473, 6015414, 6011357, 6007304, 6003252, 5999204, 5995159, 5991116, 5987076, 5983038, 5979003, 5974971, 5970942, 5966916, 5962892, 5958871, 5954852, 5950836, 5946823, 5942813, 5938806, 5934801, 5930799, 5926799, 5922802, 5918808, 5914817, 5910828, 5906842, 5902859, 5898878, 5894900, 5890925, 5886952, 5882982, 5879015, 5875051, 5871089, 5867129, 5863173, 5859219, 5855268, 5851319, 5847373, 5843430, 5839490, 5835552, 5831616, 5827684, 5823754, 5819827, 5815902, 5811980, 5808061, 5804144, 5800230, 5796318, 5792410, 5788503, 5784600, 5780699, 5776801, 5772905, 5769012, 5765122, 5761234, 5757349, 5753466, 5749586, 5745709, 5741835, 5737962, 5734093, 5730226, 5726362, 5722500, 5718641, 5714785, 5710931, 5707080, 5703231, 5699385, 5695542, 5691701, 5687863, 5684027, 5680194, 5676364, 5672536, 5668710, 5664888, 5661067, 5657250, 5653435, 5649622, 5645813, 5642005, 5638201, 5634398, 5630599, 5626802, 5623007, 5619215, 5615426, 5611639, 5607855, 5604073, 5600294, 5596517, 5592743, 5588972, 5585203, 5581436, 5577673, 5573911, 5570152, 5566396, 5562642, 5558891, 5555143, 5551396, 5547653, 5543912, 5540173, 5536437, 5532703, 5528972, 5525244, 5521518, 5517794, 5514073, 5510355, 5506639, 5502926, 5499215, 5495506, 5491800, 5488097, 5484396, 5480697, 5477002, 5473308, 5469617, 5465929, 5462243, 5458559, 5454878, 5451200, 5447523, 5443850, 5440179, 5436510, 5432844, 5429180, 5425519, 5421860, 5418204, 5414550, 5410899, 5407250, 5403604, 5399960, 5396318, 5392679, 5389043, 5385408, 5381777, 5378147, 5374521, 5370896, 5367274, 5363655, 5360038, 5356423, 5352811, 5349201, 5345594, 5341989, 5338387, 5334787, 5331189, 5327594, 5324002, 5320411, 5316823, 5313238, 5309655, 5306074, 5302496, 5298920, 5295347, 5291776, 5288207, 5284641, 5281078, 5277516, 5273957, 5270401, 5266847, 5263295, 5259746, 5256199, 5252654, 5249112, 5245572, 5242035, 5238500, 5234967, 5231437, 5227909, 5224383, 5220860, 5217340, 5213821, 5210305, 5206792, 5203280, 5199772, 5196265, 5192761, 5189259, 5185760, 5182263, 5178768, 5175276, 5171786, 5168298, 5164813, 5161330, 5157849, 5154371, 5150895, 5147422, 5143950, 5140481, 5137015, 5133551, 5130089, 5126629, 5123172, 5119717, 5116265, 5112815, 5109367, 5105921, 5102478, 5099037, 5095599, 5092162, 5088728, 5085297, 5081867, 5078440, 5075016, 5071593, 5068173, 5064756, 5061340, 5057927, 5054516, 5051107, 5047701, 5044297, 5040896, 5037496, 5034099, 5030704, 5027312, 5023922, 5020534, 5017148, 5013765, 5010384, 5007005, 5003628, 5000254, 4996882, 4993513, 4990145, 4986780, 4983417, 4980056, 4976698, 4973342, 4969988, 4966637, 4963287, 4959940, 4956596, 4953253, 4949913, 4946575, 4943239, 4939906, 4936574, 4933245, 4929918, 4926594, 4923272, 4919952, 4916634, 4913318, 4910005, 4906694, 4903385, 4900078, 4896774, 4893472, 4890172, 4886874, 4883578, 4880285, 4876994, 4873705, 4870419, 4867134, 4863852, 4860572, 4857294, 4854019, 4850745, 4847474, 4844205, 4840939, 4837674, 4834412, 4831152, 4827894, 4824638, 4821384, 4818133, 4814884, 4811637, 4808392, 4805150, 4801909, 4798671, 4795435, 4792201, 4788970, 4785740, 4782513, 4779288, 4776065, 4772844, 4769625, 4766409, 4763195, 4759983, 4756773, 4753565, 4750359, 4747156, 4743955, 4740755, 4737558, 4734364, 4731171, 4727980, 4724792, 4721606, 4718422, 4715240, 4712060, 4708883, 4705707, 4702534, 4699363, 4696194, 4693027, 4689862, 4686699, 4683539, 4680380, 4677224, 4674070, 4670918, 4667768, 4664620, 4661475, 4658331, 4655190, 4652051, 4648913, 4645778, 4642645, 4639515, 4636386, 4633259, 4630135, 4627013, 4623892, 4620774, 4617658, 4614544, 4611432, 4608322, 4605215, 4602109, 4599006, 4595904, 4592805, 4589708, 4586613, 4583520, 4580429, 4577340, 4574253, 4571169, 4568086, 4565005, 4561927, 4558851, 4555776, 4552704, 4549634, 4546566, 4543500, 4540436, 4537374, 4534314, 4531256, 4528201, 4525147, 4522096, 4519046, 4515999, 4512953, 4509910, 4506869, 4503829, 4500792, 4497757, 4494724, 4491693, 4488664, 4485637, 4482612, 4479589, 4476568, 4473549, 4470533, 4467518, 4464505, 4461494, 4458486, 4455479, 4452475, 4449472, 4446472, 4443473, 4440477, 4437482, 4434490, 4431499, 4428511, 4425524, 4422540, 4419558, 4416577, 4413599, 4410623, 4407648, 4404676, 4401706, 4398737, 4395771, 4392807, 4389844, 4386884, 4383926, 4380969, 4378015, 4375063, 4372112, 4369164, 4366217, 4363273, 4360331, 4357390, 4354452, 4351515, 4348581, 4345648, 4342718, 4339789, 4336863, 4333938, 4331015, 4328095, 4325176, 4322259, 4319345, 4316432, 4313521, 4310612, 4307705, 4304800, 4301897, 4298996, 4296097, 4293200, 4290305, 4287412, 4284521, 4281631, 4278744, 4275859, 4272975, 4270094, 4267214, 4264336, 4261461, 4258587, 4255715, 4252845, 4249977, 4247111, 4244247, 4241385, 4238525, 4235667, 4232810, 4229956, 4227103, 4224253, 4221404, 4218557, 4215712, 4212870, 4210029, 4207190, 4204352, 4201517, 4198684, 4195852, 4193023, 4190195, 4187370, 4184546, 4181724, 4178904, 4176086, 4173270, 4170455, 4167643, 4164833, 4162024, 4159217, 4156412, 4153610, 4150809, 4148009, 4145212, 4142417, 4139623, 4136832, 4134042, 4131254, 4128468, 4125684, 4122902, 4120122, 4117343, 4114567, 4111792, 4109019, 4106248, 4103479, 4100712, 4097947, 4095183, 4092422, 4089662, 4086904, 4084148, 4081394, 4078641, 4075891, 4073142, 4070396, 4067651, 4064908, 4062166, 4059427, 4056689, 4053954, 4051220, 4048488, 4045758, 4043030, 4040303, 4037579, 4034856, 4032135, 4029416, 4026698, 4023983, 4021269, 4018558, 4015848, 4013140, 4010433, 4007729, 4005026, 4002325, 3999626, 3996929, 3994234, 3991540, 3988849, 3986159, 3983471, 3980784, 3978100, 3975417, 3972736, 3970057, 3967380, 3964705, 3962031, 3959359, 3956689, 3954021, 3951354, 3948690, 3946027, 3943366, 3940707, 3938049, 3935394, 3932740, 3930088, 3927437, 3924789, 3922142, 3919497, 3916854, 3914213, 3911573, 3908935, 3906299, 3903665, 3901033, 3898402, 3895773, 3893146, 3890520, 3887897, 3885275, 3882655, 3880037, 3877420, 3874805, 3872192, 3869581, 3866972, 3864364, 3861758, 3859154, 3856551, 3853951, 3851352, 3848754, 3846159, 3843565, 3840973, 3838383, 3835795, 3833208, 3830623, 3828040, 3825458, 3822879, 3820301, 3817724, 3815150, 3812577, 3810006, 3807437, 3804869, 3802303, 3799739, 3797177, 3794616, 3792057, 3789500, 3786945, 3784391, 3781839, 3779289, 3776740, 3774193, 3771648, 3769104, 3766563, 3764023, 3761484, 3758948, 3756413, 3753880, 3751348, 3748819, 3746291, 3743764, 3741240, 3738717, 3736195, 3733676, 3731158, 3728642, 3726127, 3723615, 3721104, 3718594, 3716087, 3713581, 3711076, 3708574, 3706073, 3703574, 3701076, 3698580, 3696086, 3693594, 3691103, 3688614, 3686126, 3683640, 3681156, 3678674, 3676193, 3673714, 3671237, 3668761, 3666287, 3663815, 3661344, 3658875, 3656407, 3653942, 3651478, 3649015, 3646554, 3644095, 3641638, 3639182, 3636728, 3634276, 3631825, 3629376, 3626928, 3624482, 3622038, 3619596, 3617155, 3614715, 3612278, 3609842, 3607408, 3604975, 3602544, 3600114, 3597687, 3595260, 3592836, 3590413, 3587992, 3585572, 3583154, 3580738, 3578323, 3575910, 3573499, 3571089, 3568681, 3566274, 3563869, 3561466, 3559064, 3556664, 3554266, 3551869, 3549474, 3547080, 3544688, 3542298, 3539909, 3537522, 3535136, 3532752, 3530370, 3527989, 3525610, 3523232, 3520857, 3518482, 3516110, 3513738, 3511369, 3509001, 3506635, 3504270, 3501907, 3499545, 3497185, 3494827, 3492470, 3490115, 3487761, 3485409, 3483059, 3480710, 3478363, 3476017, 3473673, 3471331, 3468990, 3466650, 3464313, 3461976, 3459642, 3457309, 3454977, 3452647, 3450319, 3447992, 3445667, 3443344, 3441022, 3438701, 3436382, 3434065, 3431749, 3429435, 3427122, 3424811, 3422501, 3420193, 3417887, 3415582, 3413279, 3410977, 3408677, 3406378, 3404081, 3401785, 3399491, 3397199, 3394908, 3392619, 3390331, 3388045, 3385760, 3383477, 3381195, 3378915, 3376636, 3374359, 3372084, 3369810, 3367537, 3365266, 3362997, 3360729, 3358463, 3356198, 3353935, 3351673, 3349413, 3347154, 3344897, 3342641, 3340387, 3338134, 3335883, 3333634, 3331386, 3329139, 3326894, 3324650, 3322408, 3320168, 3317929, 3315691, 3313455, 3311221, 3308988, 3306757, 3304527, 3302298, 3300071, 3297846, 3295622, 3293400, 3291179, 3288959, 3286741, 3284525, 3282310, 3280096, 3277884, 3275674, 3273465, 3271258, 3269052, 3266847, 3264644, 3262442, 3260242, 3258044, 3255847, 3253651, 3251457, 3249264, 3247073, 3244884, 3242695, 3240509, 3238323, 3236140, 3233957, 3231776, 3229597, 3227419, 3225243, 3223068, 3220894, 3218722, 3216552, 3214382, 3212215, 3210049, 3207884, 3205721, 3203559, 3201398, 3199240, 3197082, 3194926, 3192772, 3190619, 3188467, 3186317, 3184168, 3182021, 3179875, 3177731, 3175588, 3173446, 3171306, 3169168, 3167030, 3164895, 3162760, 3160628, 3158496, 3156366, 3154238, 3152111, 3149985, 3147861, 3145738, 3143617, 3141497, 3139378, 3137261, 3135146, 3133031, 3130919, 3128807, 3126697, 3124589, 3122482, 3120376, 3118272, 3116169, 3114067, 3111967, 3109869, 3107772, 3105676, 3103582, 3101489, 3099397, 3097307, 3095218, 3093131, 3091045, 3088961, 3086878, 3084796, 3082716, 3080637, 3078559, 3076483, 3074409, 3072336, 3070264, 3068193, 3066124, 3064056, 3061990, 3059925, 3057862, 3055800, 3053739, 3051680, 3049622, 3047565, 3045510, 3043456, 3041404, 3039353, 3037303, 3035255, 3033208, 3031163, 3029119, 3027076, 3025035, 3022995, 3020956, 3018919, 3016883, 3014849, 3012816, 3010784, 3008754, 3006725, 3004697, 3002671, 3000646, 2998622, 2996600, 2994579, 2992560, 2990542, 2988525, 2986510, 2984496, 2982483, 2980472, 2978462, 2976454, 2974446, 2972441, 2970436, 2968433, 2966431, 2964431, 2962432, 2960434, 2958437, 2956442, 2954449, 2952456, 2950465, 2948476, 2946487, 2944500, 2942515, 2940530, 2938547, 2936566, 2934585, 2932607, 2930629, 2928653, 2926678, 2924704, 2922732, 2920761, 2918791, 2916823, 2914856, 2912890, 2910926, 2908963, 2907001, 2905041, 2903082, 2901124, 2899168, 2897213, 2895259, 2893306, 2891355, 2889405, 2887457, 2885510, 2883564, 2881619, 2879676, 2877734, 2875794, 2873854, 2871916, 2869980, 2868044, 2866110, 2864177, 2862246, 2860316, 2858387, 2856459, 2854533, 2852608, 2850684, 2848762, 2846841, 2844921, 2843002, 2841085, 2839169, 2837255, 2835341, 2833429, 2831519, 2829609, 2827701, 2825794, 2823889, 2821984, 2820081, 2818179, 2816279, 2814380, 2812482, 2810585, 2808690, 2806796, 2804903, 2803012, 2801121, 2799232, 2797345, 2795458, 2793573, 2791689, 2789807, 2787925, 2786045, 2784167, 2782289, 2780413, 2778538, 2776664, 2774792, 2772920, 2771050, 2769182, 2767314, 2765448, 2763583, 2761720, 2759857, 2757996, 2756136, 2754278, 2752420, 2750564, 2748709, 2746856, 2745003, 2743152, 2741302, 2739454, 2737606, 2735760, 2733915, 2732072, 2730229, 2728388, 2726548, 2724709, 2722872, 2721036, 2719201, 2717367, 2715535, 2713703, 2711873, 2710045, 2708217, 2706391, 2704566, 2702742, 2700919, 2699098, 2697278, 2695459, 2693641, 2691825, 2690009, 2688195, 2686383, 2684571, 2682761, 2680951, 2679144, 2677337, 2675531, 2673727, 2671924, 2670122, 2668322, 2666522, 2664724, 2662927, 2661131, 2659337, 2657543, 2655751, 2653960, 2652171, 2650382, 2648595, 2646809, 2645024, 2643240, 2641458, 2639676, 2637896, 2636117, 2634340, 2632563, 2630788, 2629014, 2627241, 2625469, 2623699, 2621929, 2620161, 2618394, 2616629, 2614864, 2613101, 2611339, 2609578, 2607818, 2606059, 2604302, 2602545, 2600790, 2599037, 2597284, 2595532, 2593782, 2592033, 2590285, 2588538, 2586793, 2585048, 2583305, 2581563, 2579822, 2578082, 2576344, 2574606, 2572870, 2571135, 2569401, 2567669, 2565937, 2564207, 2562477, 2560749, 2559023, 2557297, 2555572, 2553849, 2552127, 2550406, 2548686, 2546967, 2545249, 2543533, 2541818, 2540104, 2538391, 2536679, 2534968, 2533259, 2531551, 2529843, 2528137, 2526433, 2524729, 2523026, 2521325, 2519625, 2517925, 2516227, 2514531, 2512835, 2511140, 2509447, 2507755, 2506064, 2504374, 2502685, 2500997, 2499310, 2497625, 2495941, 2494258, 2492576, 2490895, 2489215, 2487536, 2485859, 2484182, 2482507, 2480833, 2479160, 2477488, 2475818, 2474148, 2472480, 2470812, 2469146, 2467481, 2465817, 2464154, 2462492, 2460832, 2459172, 2457514, 2455857, 2454201, 2452546, 2450892, 2449239, 2447587, 2445937, 2444287, 2442639, 2440992, 2439346, 2437701, 2436057, 2434414, 2432772, 2431132, 2429492, 2427854, 2426217, 2424581, 2422945, 2421312, 2419679, 2418047, 2416416, 2414787, 2413158, 2411531, 2409905, 2408280, 2406656, 2405033, 2403411, 2401790, 2400170, 2398552, 2396934, 2395318, 2393703, 2392088, 2390475, 2388863, 2387252, 2385642, 2384034, 2382426, 2380819, 2379214, 2377609, 2376006, 2374404, 2372803, 2371202, 2369603, 2368005, 2366409, 2364813, 2363218, 2361624, 2360032, 2358440, 2356850, 2355261, 2353672, 2352085, 2350499, 2348914, 2347330, 2345747, 2344165, 2342584, 2341004, 2339426, 2337848, 2336272, 2334696, 2333122, 2331548, 2329976, 2328405, 2326835, 2325265, 2323697, 2322130, 2320564, 2319000, 2317436, 2315873, 2314311, 2312751, 2311191, 2309632, 2308075, 2306518, 2304963, 2303409, 2301855, 2300303, 2298752, 2297202, 2295652, 2294104, 2292557, 2291011, 2289466, 2287922, 2286380, 2284838, 2283297, 2281757, 2280218, 2278681, 2277144, 2275609, 2274074, 2272540, 2271008, 2269476, 2267946, 2266417, 2264888, 2263361, 2261835, 2260309, 2258785, 2257262, 2255740, 2254218, 2252698, 2251179, 2249661, 2248144, 2246628, 2245113, 2243599, 2242086, 2240574, 2239063, 2237553, 2236044, 2234536, 2233029, 2231523, 2230019, 2228515, 2227012, 2225510, 2224009, 2222510, 2221011, 2219513, 2218016, 2216521, 2215026, 2213532, 2212039, 2210548, 2209057, 2207567, 2206079, 2204591, 2203104, 2201619, 2200134, 2198650, 2197168, 2195686, 2194205, 2192725, 2191247, 2189769, 2188292, 2186817, 2185342, 2183868, 2182396, 2180924, 2179453, 2177983, 2176515, 2175047, 2173580, 2172114, 2170650, 2169186, 2167723, 2166261, 2164800, 2163341, 2161882, 2160424, 2158967, 2157511, 2156056, 2154602, 2153149, 2151697, 2150246, 2148796, 2147347, 2145899, 2144452, 2143006, 2141561, 2140116, 2138673, 2137231, 2135790, 2134349, 2132910, 2131472, 2130034, 2128598, 2127163, 2125728, 2124295, 2122862, 2121430, 2120000, 2118570 }; static void update_sample_filter(const AV_HQMixerData *const mixer_data, AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp, tmp_round; if ((channel_block->filter_cutoff == 4095) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = ((nat_freq * (INT64_C(16777216) - damp_factor)) + ((int64_t) mix_rate << 23)) / ((int64_t) mix_rate << 24); tmp_round = nat_freq >> 1; if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); add_128(tmp_128, tmp_round); d = divs_128(tmp_128, nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz add_128(tmp_128, tmp_round); e = ((divu_128(tmp_128, nat_freq) + tmp_round) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; tmp_round = tmp >> 1; channel_block->filter_c1 = (INT64_C(281474976710656) + tmp_round) / tmp; channel_block->filter_c2 = (((d + e + e) << 24) + tmp_round) / tmp; channel_block->filter_c3 = (((-e) << 24) + tmp_round) / tmp; } static void set_sample_filter(const AV_HQMixerData *const mixer_data, AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint16_t cutoff, uint16_t damping) { if (cutoff > 4095) cutoff = 4095; if (damping > 4095) damping = 4095; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_info, channel_block); } static av_cold AVMixerData *init(AVMixerContext *const mixctx, const char *args, void *opaque) { AV_HQMixerData *hq_mixer_data; AV_HQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned real16bit = 1, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(hq_mixer_data = av_mallocz(sizeof(AV_HQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(hq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mixer_data.mixctx = mixctx; buf_size = hq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=false;") || av_stristr(args, "real16bit=disabled;")) real16bit = 0; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->channel_info = channel_info; hq_mixer_data->mixer_data.channels_in = channels_in; hq_mixer_data->channels_in = channels_in; hq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mix_buf_size = mix_buf_mem_size; hq_mixer_data->buf = buf; hq_mixer_data->buf_size = buf_size; hq_mixer_data->mixer_data.mix_buf_size = hq_mixer_data->buf_size; hq_mixer_data->mixer_data.mix_buf = hq_mixer_data->buf; channel_rate = hq_mixer_data->mixer_data.mixctx->frequency; hq_mixer_data->mixer_data.rate = channel_rate; hq_mixer_data->mix_rate = channel_rate; hq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->filter_buf = buf; for (i = hq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } return (AVMixerData *) hq_mixer_data; } static av_cold int uninit(AVMixerData *const mixer_data) { AV_HQMixerData *hq_mixer_data = (AV_HQMixerData *) mixer_data; if (!hq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->filter_buf); av_free(hq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *const mixer_data, const uint32_t tempo) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t channel_rate = hq_mixer_data->mix_rate * 10; uint64_t pass_value; hq_mixer_data->mixer_data.tempo = tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) hq_mixer_data->mix_rate_frac >> 16); hq_mixer_data->pass_len = (uint64_t) pass_value / hq_mixer_data->mixer_data.tempo; hq_mixer_data->pass_len_frac = (((uint64_t) pass_value % hq_mixer_data->mixer_data.tempo) << 32) / hq_mixer_data->mixer_data.tempo; return tempo; } static av_cold uint32_t set_rate(AVMixerData *const mixer_data, const uint32_t mix_rate, const uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t buf_size, old_mix_rate, mix_rate_frac; hq_mixer_data->mixer_data.rate = mix_rate; buf_size = hq_mixer_data->mixer_data.mix_buf_size; hq_mixer_data->mixer_data.channels_out = channels; if ((hq_mixer_data->buf_size * hq_mixer_data->channels_out) != (buf_size * channels)) { int32_t *buf = hq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = hq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return hq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return hq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); hq_mixer_data->mixer_data.mix_buf = buf; hq_mixer_data->mixer_data.mix_buf_size = buf_size; hq_mixer_data->filter_buf = filter_buf; } hq_mixer_data->channels_out = channels; hq_mixer_data->buf = hq_mixer_data->mixer_data.mix_buf; hq_mixer_data->buf_size = hq_mixer_data->mixer_data.mix_buf_size; if (hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { old_mix_rate = mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (hq_mixer_data->mix_rate != old_mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = old_mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / old_mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % old_mix_rate) << 32) / old_mix_rate; channel_info->next.advance = channel_info->next.rate / old_mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % old_mix_rate) << 32) / old_mix_rate; update_sample_filter(hq_mixer_data, channel_info, &channel_info->current); update_sample_filter(hq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return mix_rate; } static av_cold uint32_t set_volume(AVMixerData *const mixer_data, const uint32_t amplify, const uint32_t left_volume, const uint32_t right_volume, const uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { int32_t *volume_lut = hq_mixer_data->volume_lut; int64_t volume_mult = 0; int32_t volume_div = channels << 8; uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; - *volume_lut++ = ((((int64_t) volume * volume_mult)) + (volume_div >> 1)) / volume_div; + *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 4095, 0); set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 4095, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *const mixer_data, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, 4095, 0); } static av_cold void get_both_channels(const AVMixerData *const mixer_data, AVMixerChannel *const mixer_channel_current, AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel_current, const AVMixerChannel *const mixer_channel_next, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *const mixer_data, const AVMixerChannel *const mixer_channel, const uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (const AV_HQMixerData *const) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *const mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *const mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *const) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(hq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler)
BastyCDGS/ffmpeg-soc
7c6c826c20b7a7bfaf7896b375743ece80cf5b55
Fixed a small nit in high quality mixer and fixed memory allocation error message for virtual channels in AVSequencer module.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 4dfae9f..e06458e 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -3196,1025 +3196,1025 @@ static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const stru const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; - interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); + interpolate_div += ((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31; *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } diff --git a/libavsequencer/module.c b/libavsequencer/module.c index 05f9c98..74421b9 100644 --- a/libavsequencer/module.c +++ b/libavsequencer/module.c @@ -1,473 +1,473 @@ /* * Implement AVSequencer module stuff * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Implement AVSequencer module stuff. */ #include "libavutil/log.h" #include "libavformat/avformat.h" #include "libavsequencer/avsequencer.h" #include "libavsequencer/player.h" static const char *module_name(void *p) { AVSequencerModule *module = p; AVMetadataTag *tag = av_metadata_get(module->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Module"; } static const AVClass avseq_module_class = { "AVSequencer Module", module_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerModule *avseq_module_create(void) { return av_mallocz(sizeof(AVSequencerModule) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_module_destroy(AVSequencerModule *module) { if (module) av_metadata_free(&module->metadata); av_free(module); } int avseq_module_open(AVSequencerContext *avctx, AVSequencerModule *module) { AVSequencerModule **module_list; uint16_t modules; if (!avctx) return AVERROR_INVALIDDATA; module_list = avctx->module_list; modules = avctx->modules; if (!(module && ++modules)) { return AVERROR_INVALIDDATA; } else if (!(module_list = av_realloc(module_list, (modules * sizeof(AVSequencerModule *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(avctx, AV_LOG_ERROR, "Cannot allocate module storage container.\n"); return AVERROR(ENOMEM); } module->av_class = &avseq_module_class; if (!module->channels) module->channels = 64; module_list[modules - 1] = module; avctx->module_list = module_list; avctx->modules = modules; return 0; } void avseq_module_close(AVSequencerContext *avctx, AVSequencerModule *module) { AVSequencerModule **module_list; uint16_t modules, i; if (!(avctx && module)) return; module_list = avctx->module_list; modules = avctx->modules; for (i = 0; i < modules; ++i) { if (module_list[i] == module) break; } if (modules && (i != modules)) { AVSequencerModule *last_module = module_list[--modules]; if (!modules) { av_freep(&avctx->module_list); avctx->modules = 0; } else if (!(module_list = av_realloc(module_list, (modules * sizeof(AVSequencerModule *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_modules = i + 1; module_list = avctx->module_list; if (copy_modules < modules) memmove(module_list + i, module_list + copy_modules, (modules - copy_modules) * sizeof(AVSequencerModule *)); module_list[modules - 1] = NULL; } else { const unsigned copy_modules = i + 1; if (copy_modules < modules) { memmove(module_list + i, module_list + copy_modules, (modules - copy_modules) * sizeof(AVSequencerModule *)); module_list[modules - 1] = last_module; } avctx->module_list = module_list; avctx->modules = modules; } } i = module->songs; while (i--) { AVSequencerSong *song = module->song_list[i]; avseq_song_close(module, song); avseq_song_destroy(song); } i = module->instruments; while (i--) { AVSequencerInstrument *instrument = module->instrument_list[i]; avseq_instrument_close(module, instrument); avseq_instrument_destroy(instrument); } i = module->envelopes; while (i--) { AVSequencerEnvelope *envelope = module->envelope_list[i]; avseq_envelope_close(module, envelope); avseq_envelope_destroy(envelope); } i = module->keyboards; while (i--) { AVSequencerKeyboard *keyboard = module->keyboard_list[i]; avseq_keyboard_close(module, keyboard); avseq_keyboard_destroy(keyboard); } i = module->arpeggios; while (i--) { AVSequencerArpeggio *arpeggio = module->arpeggio_list[i]; avseq_arpeggio_close(module, arpeggio); avseq_arpeggio_destroy(arpeggio); } } int avseq_module_play(AVSequencerContext *avctx, AVMixerContext *mixctx, AVSequencerModule *module, AVSequencerSong *song, const char *args, void *opaque, uint32_t mode) { AVSequencerPlayerGlobals *player_globals; AVSequencerPlayerHostChannel *player_host_channel; AVSequencerPlayerChannel *player_channel; AVMixerData *mixer_data; uint16_t *gosub_stack = NULL; uint16_t *loop_stack = NULL; uint16_t *new_gosub_stack = NULL; uint16_t *new_loop_stack = NULL; uint64_t volume_boost; uint32_t tempo; if (!(avctx && module && song)) return AVERROR_INVALIDDATA; player_globals = avctx->player_globals; player_host_channel = avctx->player_host_channel; player_channel = avctx->player_channel; mixer_data = avctx->player_mixer_data; if (!(player_globals = av_realloc(player_globals, sizeof(AVSequencerPlayerGlobals) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(avctx, AV_LOG_ERROR, "Cannot allocate player globals storage container.\n"); return AVERROR(ENOMEM); } else if (!(player_host_channel = av_realloc(player_host_channel, (song->channels * sizeof(AVSequencerPlayerHostChannel)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_free(player_globals); av_log(avctx, AV_LOG_ERROR, "Cannot allocate player host channel data.\n"); return AVERROR(ENOMEM); } else if (!(player_channel = av_realloc(player_channel, (module->channels * sizeof(AVSequencerPlayerChannel)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_free(player_host_channel); av_free(player_globals); - av_log(avctx, AV_LOG_ERROR, "Cannot allocate player host channel data.\n"); + av_log(avctx, AV_LOG_ERROR, "Cannot allocate player virtual channel data.\n"); return AVERROR(ENOMEM); } else if (mixctx && !(mixer_data = avseq_mixer_init(avctx, mixctx, args, opaque))) { av_free(player_channel); av_free(player_host_channel); av_free(player_globals); av_log(avctx, AV_LOG_ERROR, "Cannot allocate mixer data.\n"); } if (avctx->player_globals) { gosub_stack = player_globals->gosub_stack; loop_stack = player_globals->loop_stack; } else { memset(player_globals, 0, sizeof(AVSequencerPlayerGlobals)); } if (!avctx->player_host_channel) { if (avctx->player_globals) { if (song->channels > player_globals->stack_channels) memset(player_host_channel + player_globals->stack_channels, 0, (song->channels - player_globals->stack_channels) * sizeof(AVSequencerPlayerHostChannel)); } else { memset(player_host_channel, 0, song->channels * sizeof(AVSequencerPlayerHostChannel)); } } if (!avctx->player_channel) { if (avctx->player_globals) { if (module->channels > player_globals->virtual_channels) memset(player_channel + player_globals->virtual_channels, 0, (module->channels - player_globals->virtual_channels) * sizeof(AVSequencerPlayerChannel)); } else { memset(player_channel, 0, module->channels * sizeof(AVSequencerPlayerChannel)); } } if (!gosub_stack || (player_globals->stack_channels != song->channels) || (player_globals->gosub_stack_size != song->gosub_stack_size)) { if (!(new_gosub_stack = av_mallocz((song->channels * song->gosub_stack_size << 2) + FF_INPUT_BUFFER_PADDING_SIZE))) { avseq_mixer_uninit(avctx, mixer_data); av_free(player_channel); av_free(player_host_channel); av_free(player_globals); av_log(avctx, AV_LOG_ERROR, "Cannot allocate GoSub command stack storage container.\n"); return AVERROR(ENOMEM); } } else if (!loop_stack || (player_globals->stack_channels != song->channels) || (player_globals->loop_stack_size != song->loop_stack_size)) { if (!(new_loop_stack = av_mallocz((song->channels * song->loop_stack_size << 2) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_free(new_gosub_stack); avseq_mixer_uninit(avctx, mixer_data); av_free(player_channel); av_free(player_host_channel); av_free(player_globals); av_log(avctx, AV_LOG_ERROR, "Cannot allocate pattern loop command stack storage container.\n"); return AVERROR(ENOMEM); } } avctx->player_globals = player_globals; avctx->player_host_channel = player_host_channel; avctx->player_channel = player_channel; avctx->player_module = module; avctx->player_song = song; avctx->player_mixer_data = mixer_data; if (new_gosub_stack && gosub_stack) { uint32_t *process_stack = (uint32_t *) player_globals->gosub_stack; uint32_t *process_new_stack = (uint32_t *) new_gosub_stack; uint16_t skip_over_channel = song->channels, skip_over_stack, skip_new_stack, skip_old_stack, i; if (player_globals->stack_channels < skip_over_channel) skip_over_channel = player_globals->stack_channels; skip_over_stack = song->gosub_stack_size; if (player_globals->gosub_stack_size < skip_over_stack) skip_over_stack = player_globals->gosub_stack_size; for (i = skip_over_channel; i > 0; i--) { uint16_t j; skip_new_stack = song->gosub_stack_size; skip_old_stack = player_globals->gosub_stack_size; for (j = skip_over_stack; j > 0; j--) { *process_new_stack++ = *process_stack++; skip_new_stack--; skip_old_stack--; } process_stack += skip_old_stack; process_new_stack += skip_new_stack; } av_free(gosub_stack); } if (new_loop_stack && loop_stack) { uint32_t *process_stack = (uint32_t *) player_globals->loop_stack; uint32_t *process_new_stack = (uint32_t *) new_loop_stack; uint16_t skip_over_channel = song->channels, skip_over_stack, skip_new_stack, skip_old_stack, i; if (player_globals->stack_channels < skip_over_channel) skip_over_channel = player_globals->stack_channels; skip_over_stack = song->loop_stack_size; if (player_globals->loop_stack_size < skip_over_stack) skip_over_stack = player_globals->loop_stack_size; for (i = skip_over_channel; i > 0; i--) { uint16_t j; skip_new_stack = song->loop_stack_size; skip_old_stack = player_globals->loop_stack_size; for (j = skip_over_stack; j > 0; j--) { *process_new_stack++ = *process_stack++; skip_new_stack--; skip_old_stack--; } process_stack += skip_old_stack; process_new_stack += skip_new_stack; } av_free(loop_stack); } player_globals->gosub_stack = new_gosub_stack ? new_gosub_stack : gosub_stack; player_globals->gosub_stack_size = song->gosub_stack_size; player_globals->loop_stack = new_loop_stack ? new_loop_stack : loop_stack; player_globals->loop_stack_size = song->loop_stack_size; player_globals->stack_channels = song->channels; player_globals->virtual_channels = module->channels; player_globals->flags &= ~(AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN|AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN); if (mode) player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE; else player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE; player_globals->play_type = AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG; if (!player_globals->relative_speed) player_globals->relative_speed = 0x10000; if (!player_globals->relative_pitch) player_globals->relative_pitch = player_globals->relative_speed; tempo = avseq_song_calc_speed(avctx, song); volume_boost = ((uint64_t) module->channels * (65536*125/1000)) + (65536*75/100); mixer_data->flags |= AVSEQ_MIXER_DATA_FLAG_MIXING; if (mixctx) avseq_mixer_set_rate(mixer_data, mixctx->frequency, mixctx->channels_out); avseq_mixer_set_tempo(mixer_data, tempo); avseq_mixer_set_volume(mixer_data, volume_boost, 65536, 65536, module->channels); return 0; } void avseq_module_stop(AVSequencerContext *avctx, uint32_t mode) { if (avctx) { AVMixerData *mixer_data; if ((mixer_data = avctx->player_mixer_data)) { avctx->player_mixer_data = NULL; avseq_mixer_uninit(avctx, mixer_data); } if (mode & 1) { AVSequencerPlayerGlobals *player_globals; av_freep(&avctx->player_hook); av_freep(&avctx->player_channel); av_freep(&avctx->player_host_channel); if ((player_globals = avctx->player_globals)) { av_free(player_globals->gosub_stack); av_free(player_globals->loop_stack); } av_freep(&avctx->player_globals); } } } int avseq_module_set_channels(AVSequencerContext *avctx, AVSequencerModule *module, uint32_t channels) { if (!(avctx && module)) return AVERROR_INVALIDDATA; if (!channels) channels = 64; if (channels > 65535) channels = 65535; if ((module == avctx->player_module) && (channels != module->channels)) { AVSequencerPlayerGlobals *player_globals; AVSequencerPlayerChannel *player_channel; if ((player_channel = avctx->player_channel)) { AVSequencerSong *song; if (!(player_channel = av_realloc(player_channel, (module->channels * sizeof(AVSequencerPlayerChannel)) + FF_INPUT_BUFFER_PADDING_SIZE))) { - av_log(avctx, AV_LOG_ERROR, "Cannot allocate player host channel data.\n"); + av_log(avctx, AV_LOG_ERROR, "Cannot allocate player virtual channel data.\n"); return AVERROR(ENOMEM); } if (channels > module->channels) memset(player_channel + module->channels, 0, (channels - module->channels) * sizeof(AVSequencerPlayerChannel)); if ((song = avctx->player_song)) { AVSequencerPlayerHostChannel *player_host_channel; if ((song == avctx->player_song) && (player_host_channel = avctx->player_host_channel)) { uint16_t i, host_channel = 0; for (i = song->channels; i > 0; i--) { if (player_host_channel->virtual_channel >= channels) { AVSequencerPlayerChannel *updated_player_channel = player_channel; uint16_t j; player_host_channel->virtual_channel = 0; player_host_channel->virtual_channels = 0; for (j = channels; j > 0; j--) { if (player_channel->host_channel == host_channel) updated_player_channel->mixer.flags = 0; updated_player_channel++; } } host_channel++; player_host_channel++; } } } avctx->player_channel = player_channel; if ((player_globals = avctx->player_globals)) player_globals->virtual_channels = module->channels; } } module->channels = channels; return 0; }
BastyCDGS/ffmpeg-soc
973cd91f346a7c5e836e7eb0c2aacfdbd1fc13a5
Some more nit fixes in the low quality mixer and player.
diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 4f1f81c..10d989d 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -115,1211 +115,1211 @@ static void apply_filter(AV_LQMixerChannelInfo *const channel_info, struct Chann while (i--) { mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 4095) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } -#define MIX_FUNCTION(INIT, TYPE, OP, OFFSET_START, OFFSET_END, SKIP, \ - NEXTS, NEXTA, NEXTI, SHIFTS, SHIFTN, SHIFTB) \ - const TYPE *sample = (const TYPE *) channel_block->data; \ - int32_t *mix_buf = *buf; \ - uint32_t curr_offset = *offset; \ - uint32_t curr_frac = *fraction; \ - uint32_t i; \ - INIT; \ - \ - if (advance) { \ - if (mixer_data->interpolation) { \ - int32_t smp; \ - int32_t interpolate_div; \ - \ - OFFSET_START; \ - i = (len >> 1) + 1; \ - \ - if (len & 1) \ - goto get_second_advance_interpolated_sample; \ - \ - i--; \ - \ - do { \ - uint32_t interpolate_offset; \ - \ - curr_frac += adv_frac; \ - interpolate_offset = advance + ((curr_frac < adv_frac) ? 1 : 0); \ - smp = 0; \ - interpolate_div = 0; \ - \ - do { \ - NEXTA; \ - interpolate_div++; \ - } while (--interpolate_offset); \ - \ - smp /= interpolate_div; \ - SHIFTS; \ -get_second_advance_interpolated_sample: \ - curr_frac += adv_frac; \ - interpolate_offset = advance + ((curr_frac < adv_frac) ? 1 : 0); \ - smp = 0; \ - interpolate_div = 0; \ - \ - do { \ - NEXTA; \ - interpolate_div++; \ - } while (--interpolate_offset); \ - \ - smp /= interpolate_div; \ - SHIFTS; \ - } while (--i); \ - \ - *buf = mix_buf; \ - OFFSET_END; \ - *fraction = curr_frac; \ - } else { \ - i = (len >> 1) + 1; \ - \ - if (len & 1) \ - goto get_second_advance_sample; \ - \ - i--; \ - \ - do { \ - SKIP; \ - curr_frac += adv_frac; \ - curr_offset OP advance + ((curr_frac < adv_frac) ? 1 : 0); \ -get_second_advance_sample: \ - SKIP; \ - curr_frac += adv_frac; \ - curr_offset OP advance + ((curr_frac < adv_frac) ? 1 : 0); \ - } while (--i); \ - \ - *buf = mix_buf; \ - *offset = curr_offset; \ - *fraction = curr_frac; \ - } \ - } else { \ - int32_t smp; \ - \ - if (mixer_data->interpolation > 1) { \ - uint32_t interpolate_frac, interpolate_count; \ - int32_t interpolate_div; \ - int64_t smp_value; \ - \ - OFFSET_START; \ - NEXTS; \ - smp_value = 0; \ - \ - if (len > 1) { \ - NEXTI; \ - } \ - \ - interpolate_div = smp_value >> 32; \ - interpolate_frac = smp_value; \ - interpolate_count = 0; \ - \ - i = (len >> 1) + 1; \ - \ - if (len & 1) \ - goto get_second_interpolated_sample; \ - \ - i--; \ - \ - do { \ - SHIFTS; \ - curr_frac += adv_frac; \ - \ - if (curr_frac < adv_frac) { \ - NEXTS; \ - NEXTI; \ - \ - interpolate_div = smp_value >> 32; \ - interpolate_frac = smp_value; \ - interpolate_count = 0; \ - } else { \ - smp += interpolate_div; \ - interpolate_count += interpolate_frac; \ - \ - if (interpolate_count < interpolate_frac) { \ - smp++; \ - \ - if (interpolate_div < 0) \ - smp -= 2; \ - } \ - } \ -get_second_interpolated_sample: \ - SHIFTS; \ - curr_frac += adv_frac; \ - \ - if (curr_frac < adv_frac) { \ - NEXTS; \ - smp_value = 0; \ - \ - if (i > 1) { \ - NEXTI; \ - } \ - \ - interpolate_div = smp_value >> 32; \ - interpolate_frac = smp_value; \ - interpolate_count = 0; \ - } else { \ - smp += interpolate_div; \ - interpolate_count += interpolate_frac; \ - \ - if (interpolate_count < interpolate_frac) { \ - smp++; \ - \ - if (interpolate_div < 0) \ - smp -= 2; \ - } \ - } \ - } while (--i); \ - \ - *buf = mix_buf; \ - OFFSET_END; \ - *fraction = curr_frac; \ - } else { \ - OFFSET_START; \ - SHIFTN; \ - i = (len >> 1) + 1; \ - \ - if (len & 1) \ - goto get_second_sample; \ - \ - i--; \ - \ - do { \ - SHIFTB; \ - curr_frac += adv_frac; \ - \ - if (curr_frac < adv_frac) { \ - SHIFTN; \ - } \ -get_second_sample: \ - SHIFTB; \ - curr_frac += adv_frac; \ - \ - if (curr_frac < adv_frac) { \ - SHIFTN; \ - } \ - } while (--i); \ - \ - *buf = mix_buf; \ - OFFSET_END; \ - *fraction = curr_frac; \ - } \ +#define MIX_FUNCTION(INIT, TYPE, OP, OFFSET_START, OFFSET_END, SKIP, \ + NEXTS, NEXTA, NEXTI, SHIFTS, SHIFTN, SHIFTB) \ + const TYPE *sample = (const TYPE *) channel_block->data; \ + int32_t *mix_buf = *buf; \ + uint32_t curr_offset = *offset; \ + uint32_t curr_frac = *fraction; \ + uint32_t i; \ + INIT; \ + \ + if (advance) { \ + if (mixer_data->interpolation) { \ + int32_t smp; \ + int32_t interpolate_div; \ + \ + OFFSET_START; \ + i = (len >> 1) + 1; \ + \ + if (len & 1) \ + goto get_second_advance_interpolated_sample; \ + \ + i--; \ + \ + do { \ + uint32_t interpolate_offset; \ + \ + curr_frac += adv_frac; \ + interpolate_offset = advance + (curr_frac < adv_frac); \ + smp = 0; \ + interpolate_div = 0; \ + \ + do { \ + NEXTA; \ + interpolate_div++; \ + } while (--interpolate_offset); \ + \ + smp /= interpolate_div; \ + SHIFTS; \ +get_second_advance_interpolated_sample: \ + curr_frac += adv_frac; \ + interpolate_offset = advance + (curr_frac < adv_frac); \ + smp = 0; \ + interpolate_div = 0; \ + \ + do { \ + NEXTA; \ + interpolate_div++; \ + } while (--interpolate_offset); \ + \ + smp /= interpolate_div; \ + SHIFTS; \ + } while (--i); \ + \ + *buf = mix_buf; \ + OFFSET_END; \ + *fraction = curr_frac; \ + } else { \ + i = (len >> 1) + 1; \ + \ + if (len & 1) \ + goto get_second_advance_sample; \ + \ + i--; \ + \ + do { \ + SKIP; \ + curr_frac += adv_frac; \ + curr_offset OP advance + (curr_frac < adv_frac); \ +get_second_advance_sample: \ + SKIP; \ + curr_frac += adv_frac; \ + curr_offset OP advance + (curr_frac < adv_frac); \ + } while (--i); \ + \ + *buf = mix_buf; \ + *offset = curr_offset; \ + *fraction = curr_frac; \ + } \ + } else { \ + int32_t smp; \ + \ + if (mixer_data->interpolation > 1) { \ + uint32_t interpolate_frac, interpolate_count; \ + int32_t interpolate_div; \ + int64_t smp_value; \ + \ + OFFSET_START; \ + NEXTS; \ + smp_value = 0; \ + \ + if (len > 1) { \ + NEXTI; \ + } \ + \ + interpolate_div = smp_value >> 32; \ + interpolate_frac = smp_value; \ + interpolate_count = 0; \ + \ + i = (len >> 1) + 1; \ + \ + if (len & 1) \ + goto get_second_interpolated_sample; \ + \ + i--; \ + \ + do { \ + SHIFTS; \ + curr_frac += adv_frac; \ + \ + if (curr_frac < adv_frac) { \ + NEXTS; \ + NEXTI; \ + \ + interpolate_div = smp_value >> 32; \ + interpolate_frac = smp_value; \ + interpolate_count = 0; \ + } else { \ + smp += interpolate_div; \ + interpolate_count += interpolate_frac; \ + \ + if (interpolate_count < interpolate_frac) { \ + smp++; \ + \ + if (interpolate_div < 0) \ + smp -= 2; \ + } \ + } \ +get_second_interpolated_sample: \ + SHIFTS; \ + curr_frac += adv_frac; \ + \ + if (curr_frac < adv_frac) { \ + NEXTS; \ + smp_value = 0; \ + \ + if (i > 1) { \ + NEXTI; \ + } \ + \ + interpolate_div = smp_value >> 32; \ + interpolate_frac = smp_value; \ + interpolate_count = 0; \ + } else { \ + smp += interpolate_div; \ + interpolate_count += interpolate_frac; \ + \ + if (interpolate_count < interpolate_frac) { \ + smp++; \ + \ + if (interpolate_div < 0) \ + smp -= 2; \ + } \ + } \ + } while (--i); \ + \ + *buf = mix_buf; \ + OFFSET_END; \ + *fraction = curr_frac; \ + } else { \ + OFFSET_START; \ + SHIFTN; \ + i = (len >> 1) + 1; \ + \ + if (len & 1) \ + goto get_second_sample; \ + \ + i--; \ + \ + do { \ + SHIFTB; \ + curr_frac += adv_frac; \ + \ + if (curr_frac < adv_frac) { \ + SHIFTN; \ + } \ +get_second_sample: \ + SHIFTB; \ + curr_frac += adv_frac; \ + \ + if (curr_frac < adv_frac) { \ + SHIFTN; \ + } \ + } while (--i); \ + \ + *buf = mix_buf; \ + OFFSET_END; \ + *fraction = curr_frac; \ + } \ } #define MIX(type) \ static void mix_##type(const AV_LQMixerData *const mixer_data, \ const struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *sample++], *mix_buf++ += smp) } MIX(mono_backwards_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, -=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *--sample, smp += *--sample, smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *--sample], *mix_buf++ += smp) } MIX(mono_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf++ += smp) } MIX(mono_backwards_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, -=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *--sample, smp += *--sample, smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *--sample >> 8], *mix_buf++ += smp) } MIX(mono_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf++ += smp) } MIX(mono_backwards_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, -=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *--sample, smp += *--sample, smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *--sample >> 24], *mix_buf++ += smp) } MIX(mono_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp) } MIX(mono_backwards_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, smp_value = bits_per_sample; bit -= bits_per_sample; if ((int32_t) bit < 0) { bit &= 31; if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *(sample-1) << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } } else { if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } } bit = smp_value; smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp) } MIX(mono_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, -=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *--sample, smp += *--sample, smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, -=, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *--sample, smp += *--sample, smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, smp_value = bits_per_sample; bit -= bits_per_sample; if ((int32_t) bit < 0) { bit &= 31; if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *(sample-1) << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } } else { if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } } bit = smp_value; smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(stereo_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int8_t smp_in; int32_t smp_right; const int8_t *const pos = sample, int8_t, +=, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *sample++, smp += *sample++, smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_left_lut[(uint8_t) smp]; *mix_buf++ += volume_right_lut[(uint8_t) smp], smp_in = *sample++; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int8_t smp_in; int32_t smp_right; const int8_t *const pos = sample, diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 2de33e0..1a8eef8 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -9778,1026 +9778,1026 @@ static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPl player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; new_player_channel->auto_pannolo_sweep = player_channel->auto_pannolo_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; new_player_channel->auto_pannolo_depth = player_channel->auto_pannolo_depth; new_player_channel->auto_pannolo_rate = player_channel->auto_pannolo_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; if (player_channel->wait_count[synth_type]--) { exec_synth_done: if ((player_channel->synth_flags & bit_mask) && !(player_channel->kill_count[synth_type]--)) return 0; return 1; } player_channel->wait_count[synth_type] = 0; if ((synth_code_line >= synth->size) || ((int8_t) player_channel->wait_type[synth_type] < 0)) goto exec_synth_done; i = 4 - 1; do { int8_t wait_volume_type; if (((wait_volume_type = ~player_channel->wait_type[synth_type]) >= 0) && (wait_volume_type == i) && (player_channel->wait_line[synth_type] == synth_code_line)) player_channel->wait_type[synth_type] = 0; } while (i--); instruction = synth_code->instruction; dst_var = synth_code->src_dst_var; instruction_data = synth_code->data; if (!instruction && !dst_var && !instruction_data) goto exec_synth_done; src_var = dst_var >> 4; dst_var &= 0x0F; synth_code_line++; if (instruction < 0) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; fx_byte = ~instruction; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = instruction_data + player_channel->variable[src_var]; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, player_channel->host_channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!effects_lut->pre_pattern_func) { instruction_data = player_host_channel->virtual_channel; player_host_channel->virtual_channel = channel; effects_lut->effect_func(avctx, player_host_channel, player_channel, player_channel->host_channel, fx_byte, data_word); player_host_channel->virtual_channel = instruction_data; } player_channel->entry_pos[synth_type] = synth_code_line; } else { uint16_t (**fx_exec_func)(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint16_t virtual_channel, uint16_t synth_code_line, const int src_var, int dst_var, uint16_t instruction_data, const int synth_type); fx_exec_func = (avctx->synth_code_exec_lut ? avctx->synth_code_exec_lut : se_lut); player_channel->entry_pos[synth_type] = fx_exec_func[(uint8_t) instruction](avctx, player_channel, channel, synth_code_line, src_var, dst_var, instruction_data, synth_type); } } while (++synth_count); return 0; } static const int8_t empty_waveform[256]; int avseq_playback_handler(AVMixerData *mixer_data) { AVSequencerContext *const avctx = (AVSequencerContext *) mixer_data->opaque; const AVSequencerModule *const module = avctx->player_module; const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; AVSequencerPlayerHostChannel *player_host_channel = avctx->player_host_channel; AVSequencerPlayerChannel *player_channel = avctx->player_channel; const AVSequencerPlayerHook *player_hook; uint16_t channel, virtual_channel; if (!(module && song && player_globals && player_host_channel && player_channel)) return 0; channel = 0; do { if (mixer_data->mixctx->get_channel) mixer_data->mixctx->get_channel(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE) { if (!player_globals->trace_count--) player_globals->trace_count = 0; return 0; } player_hook = avctx->player_hook; if (player_hook && (player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->play_type & AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG) { uint32_t play_time_calc, play_time_advance, play_time_fraction; play_time_calc = ((uint64_t) player_globals->tempo * player_globals->relative_speed) >> 16; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_time_frac += play_time_fraction; - play_time_advance += (player_globals->play_time_frac < play_time_fraction) ? 1 : 0; + play_time_advance += (player_globals->play_time_frac < play_time_fraction); player_globals->play_time += play_time_advance; play_time_calc = player_globals->tempo; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_tics_frac += play_time_fraction; - play_time_advance += (player_globals->play_tics_frac < play_time_fraction) ? 1 : 0; + play_time_advance += (player_globals->play_tics_frac < play_time_fraction); player_globals->play_tics += play_time_advance; } channel = 0; do { player_channel = avctx->player_channel + player_host_channel->virtual_channel; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE)) { const AVSequencerTrack *const old_track = player_host_channel->track; const AVSequencerTrackEffect const *old_effect = player_host_channel->effect; const uint32_t old_tempo_counter = player_host_channel->tempo_counter; const uint16_t old_row = player_host_channel->row; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE); player_host_channel->track = (const AVSequencerTrack *) player_host_channel->instrument; player_host_channel->effect = NULL; player_host_channel->row = (uint32_t) player_host_channel->sample; player_host_channel->instrument = NULL; player_host_channel->sample = NULL; get_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->tempo_counter = player_host_channel->note_delay; get_note(avctx, player_host_channel, player_channel, channel); run_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->track = old_track; player_host_channel->effect = old_effect; player_host_channel->tempo_counter = old_tempo_counter; player_host_channel->row = old_row; } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) { const uint16_t note = player_host_channel->instr_note; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT; if ((int8_t) note < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } } else { const AVSequencerInstrument *const instrument = player_host_channel->instrument; AVSequencerPlayerChannel *new_player_channel; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, note / 12, note % 12, channel))) player_channel = new_player_channel; player_channel->volume = player_host_channel->sample_note; player_channel->sub_volume = 0; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample = player_host_channel->sample; const uint32_t frequency = (uint32_t) player_host_channel->instrument; uint32_t i; uint16_t virtual_channel; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE; player_host_channel->dct = 0; player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; player_host_channel->finetune = sample->finetune; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *) &virtual_channel); sample = player_host_channel->sample; player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_host_channel->instrument = NULL; player_channel->sample = sample; player_channel->frequency = frequency; player_channel->volume = player_host_channel->instr_note; player_channel->sub_volume = 0; player_host_channel->instr_note = 0; init_new_instrument(avctx, player_host_channel, player_channel); i = -1; while (++i < module->instruments) { uint16_t smp = -1; if (!(instrument = module->instrument_list[i])) continue; while (++smp < instrument->samples) { if (!(sample = instrument->sample_list[smp])) continue; if (sample == player_channel->sample) { player_host_channel->instrument = instrument; goto instrument_found; } } } instrument_found: player_channel->instrument = player_host_channel->instrument; init_new_sample(avctx, player_host_channel, player_channel); } if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { do { process_row(avctx, player_host_channel, player_channel, channel); get_effects(avctx, player_host_channel, player_channel, channel); if (player_channel->host_channel == channel) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO)) { const int32_t slide_value = player_host_channel->vibrato_slide; player_host_channel->vibrato_slide = 0; player_channel->frequency -= slide_value; } if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO)) { int16_t slide_value = player_host_channel->tremolo_slide; player_host_channel->tremolo_slide = 0; if ((int16_t) (slide_value = (player_channel->volume - slide_value)) < 0) slide_value = 0; if (slide_value > 255) slide_value = 255; player_channel->volume = slide_value; } } } while (get_note(avctx, player_host_channel, player_channel, channel)); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { player_channel = avctx->player_channel + player_host_channel->virtual_channel; run_effects(avctx, player_host_channel, player_channel, channel); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); virtual_channel = 0; channel = 0; player_channel = avctx->player_channel; do { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { const AVSequencerSample *sample; AVSequencerPlayerEnvelope *player_envelope; uint32_t frequency, host_volume, virtual_volume; uint32_t auto_vibrato_depth, auto_vibrato_count; int32_t auto_vibrato_value; uint16_t flags, slide_envelope_value; int16_t panning, abs_panning, panning_envelope_value; player_host_channel = avctx->player_host_channel + player_channel->host_channel; player_envelope = &player_channel->vol_env; if (player_envelope->tempo) { const uint16_t volume = run_envelope(avctx, player_envelope, 1, -0x8000); if (!player_envelope->tempo) { if (!(volume >> 8)) goto turn_note_off; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } run_envelope(avctx, &player_channel->pan_env, 1, 0); slide_envelope_value = run_envelope(avctx, &player_channel->slide_env, 1, 0); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency += player_channel->slide_env_freq; if ((frequency = player_channel->frequency)) { if ((int16_t) slide_envelope_value < 0) { slide_envelope_value = -slide_envelope_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) frequency = linear_slide_down(avctx, player_channel, frequency, slide_envelope_value); else frequency = amiga_slide_down(player_channel, frequency, slide_envelope_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) { frequency = linear_slide_up(avctx, player_channel, frequency, slide_envelope_value); } else { frequency = amiga_slide_up(player_channel, frequency, slide_envelope_value); } player_channel->slide_env_freq += old_frequency - frequency; } } else { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_envelope_frequency, old_frequency; int16_t octave, note; const int16_t slide_note = (int16_t) slide_envelope_value >> 8; int32_t finetune = slide_envelope_value & 0xFF; octave = slide_note / 12; note = slide_note % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (finetune * (int32_t) next_frequency) >> 8; slide_envelope_frequency = player_channel->slide_env_freq; old_frequency = player_channel->frequency; slide_envelope_frequency += old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_envelope_frequency) >> (24 - octave); player_channel->slide_env_freq += old_frequency - frequency; } if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_FADING) { int32_t fade_out = (uint32_t) player_channel->fade_out_count; if ((fade_out -= (int32_t) player_channel->fade_out) <= 0) goto turn_note_off; player_channel->fade_out_count = fade_out; } auto_vibrato_value = run_envelope(avctx, &player_channel->auto_vib_env, player_channel->auto_vibrato_rate, 0); auto_vibrato_depth = player_channel->auto_vibrato_depth << 8; auto_vibrato_count = (uint32_t) player_channel->auto_vibrato_count + player_channel->auto_vibrato_sweep; if (auto_vibrato_count > auto_vibrato_depth) auto_vibrato_count = auto_vibrato_depth; player_channel->auto_vibrato_count = auto_vibrato_count; auto_vibrato_count >>= 8; if ((auto_vibrato_value *= (int32_t) -auto_vibrato_count)) { uint32_t old_frequency = player_channel->frequency; auto_vibrato_value >>= 7 - 2; player_channel->frequency -= player_channel->auto_vibrato_freq; if ((frequency = player_channel->frequency)) { if (auto_vibrato_value < 0) { auto_vibrato_value = -auto_vibrato_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) frequency = linear_slide_up(avctx, player_channel, frequency, auto_vibrato_value); else frequency = amiga_slide_up(player_channel, frequency, auto_vibrato_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) { frequency = linear_slide_down(avctx, player_channel, frequency, auto_vibrato_value); } else { frequency = amiga_slide_down(player_channel, frequency, auto_vibrato_value); } player_channel->auto_vibrato_freq -= old_frequency - frequency; } } if ((sample = player_channel->sample) && sample->synth) { if (!execute_synth(avctx, player_host_channel, player_channel, channel, 0)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 1)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 2)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 3)) goto turn_note_off; } if ((!player_channel->mixer.data || !player_channel->mixer.bits_per_sample) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { player_channel->mixer.pos = 0; player_channel->mixer.len = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.data = (int16_t *) &empty_waveform; player_channel->mixer.repeat_start = 0; player_channel->mixer.repeat_length = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.repeat_count = 0; player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = (sizeof (empty_waveform[0]) * 8); player_channel->mixer.flags = AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } frequency = player_channel->frequency; if (sample) { if (frequency < sample->rate_min) frequency = sample->rate_min; if (frequency > sample->rate_max) frequency = sample->rate_max; } if (!(player_channel->frequency = frequency)) { turn_note_off: player_channel->mixer.flags = 0; goto not_calculate_no_playing; } if (!(player_channel->mixer.rate = ((uint64_t) frequency * player_globals->relative_pitch) >> 16)) goto turn_note_off; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_GLOBAL_NEW_ONLY)) { player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; } host_volume = player_channel->volume; player_host_channel->virtual_channels++; virtual_channel++; if (!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) && (player_host_channel->virtual_channel == channel) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF)) host_volume = 0; host_volume *= (uint16_t) player_host_channel->track_volume * (uint16_t) player_channel->instr_volume; virtual_volume = (((uint16_t) player_channel->vol_env.value >> 8) * (uint16_t) player_channel->global_volume) * (uint16_t) player_channel->fade_out_count; player_channel->mixer.volume = player_channel->final_volume = ((uint64_t) host_volume * virtual_volume) / UINT64_C(70660093200890625); /* / (255ULL*255ULL*255ULL*255ULL*65535ULL*255ULL) */ flags = 0; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND; player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning = (uint8_t) player_channel->panning; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) { panning = (uint8_t) player_host_channel->track_panning; flags = 0; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN)) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; } player_channel->flags |= flags; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) player_channel->mixer.flags |= flags; if (panning == 255) panning++; panning_envelope_value = panning; if ((int16_t) (panning = (128 - panning)) < 0) panning = -panning; abs_panning = 128 - panning; panning = player_channel->pan_env.value >> 8; if (panning == 127) panning++; panning = 128 - (((panning * abs_panning) >> 7) + panning_envelope_value); abs_panning = (uint8_t) player_host_channel->channel_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning_envelope_value = abs_panning = ((panning * abs_panning) >> 7) + 128; if (panning_envelope_value > 255) panning_envelope_value = 255; player_channel->final_panning = panning_envelope_value; panning = 128; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_GLOBAL_SUR_PAN) player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning -= abs_panning; abs_panning = (uint8_t) player_channel->global_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning = ((panning * abs_panning) >> 7) + 128; if (panning == 256) panning--; } player_channel->mixer.panning = panning; if (mixer_data->mixctx->set_channel_volume_panning_pitch) mixer_data->mixctx->set_channel_volume_panning_pitch(mixer_data, &player_channel->mixer, channel); } not_calculate_no_playing: if (mixer_data->mixctx->set_channel_position_repeat_flags) mixer_data->mixctx->set_channel_position_repeat_flags(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); player_globals->channels = virtual_channel; if (virtual_channel > player_globals->max_channels) player_globals->max_channels = virtual_channel; channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END)) goto check_song_end_done; player_host_channel++; } while (++channel < song->channels); player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END; check_song_end_done: if (player_hook && !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && !(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END) { player_host_channel = avctx->player_host_channel; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END) { AVSequencerOrderList *order_list = song->order_list; channel = song->channels; do { AVSequencerOrderData *order_data; uint32_t i = -1; if (player_host_channel->tempo) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; while (++i < order_list->orders) { if ((order_data = order_list->order_data[i]) && (order_data != player_host_channel->order)) order_data->played = 0; } order_list++; player_host_channel++; } while (--channel); } } return 0; }
BastyCDGS/ffmpeg-soc
02470dd7b63251e8f8f10c41167335b09c58bfae
Fixed small bug issued with last commit which did not update global instrument volume correctly.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index ad14eb4..3448f84 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -8903,1025 +8903,1025 @@ static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostCh ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= player_host_channel->sample == player_channel->sample; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= player_host_channel->sample == player_channel->sample; return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; if (nna_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope * (**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope * (**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; player_channel->global_instr_volume = instrument->global_volume; player_channel->volume_swing = instrument->volume_swing; - volume = sample->global_volume * player_channel->global_volume; + volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; player_channel->auto_pannolo_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; player_channel->auto_pannolo_depth = sample->pannolo_depth; player_channel->auto_pannolo_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; } player_channel->pitch_pan_separation = instrument->pitch_pan_separation; player_channel->pitch_pan_center = instrument->pitch_pan_center; player_channel->panning_swing = instrument->panning_swing; panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } player_channel->note_swing = instrument->note_swing; player_channel->pitch_swing = instrument->pitch_swing; } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument;
BastyCDGS/ffmpeg-soc
94fa0d2ac04c9d82288fae32f02fa412f41c7e33
Implemented instrument control AVSequencer player track data effect. Fixed playback speed upon seeking if song changes BpM/SPD.
diff --git a/libavformat/iff.c b/libavformat/iff.c index 2d2d889..08d1b44 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -2516,541 +2516,542 @@ static int open_tcm1_arpl(AVFormatContext *s, AVSequencerModule *module, uint32_ ByteIOContext *pb = s->pb; uint32_t iff_size = 4; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_FORM: switch (get_le32(pb)) { case ID_ARPG: if ((res = open_arpl_arpg(s, module, iff_size)) < 0) return res; break; } break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } return 0; } static int open_arpl_arpg(AVFormatContext *s, AVSequencerModule *module, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerArpeggio *arpeggio; uint32_t iff_size = 4; uint16_t entries = 0; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; if (!(arpeggio = avseq_arpeggio_create())) return AVERROR(ENOMEM); if ((res = avseq_arpeggio_open(module, arpeggio, 1)) < 0) { avseq_arpeggio_destroy(arpeggio); return res; } while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; const char *metadata_tag = NULL; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_AHDR: entries = get_be16(pb); arpeggio->flags = get_be16(pb); arpeggio->sustain_start = get_be16(pb); arpeggio->sustain_end = get_be16(pb); arpeggio->sustain_count = get_be16(pb); arpeggio->loop_start = get_be16(pb); arpeggio->loop_end = get_be16(pb); arpeggio->loop_count = get_be16(pb); break; case ID_FORM: switch (get_le32(pb)) { case ID_ARPE: if ((res = open_arpg_arpe(s, arpeggio, iff_size)) < 0) return res; break; default: // TODO: Add unknown chunk break; } break; case ID_ANNO: case ID_TEXT: metadata_tag = "comment"; break; case ID_AUTH: metadata_tag = "artist"; break; case ID_COPYRIGHT: metadata_tag = "copyright"; break; case ID_FILE: metadata_tag = "file"; break; case ID_NAME: metadata_tag = "title"; break; default: // TODO: Add unknown chunk break; } if (metadata_tag) { if ((res = seq_get_metadata(s, &arpeggio->metadata, metadata_tag, iff_size)) < 0) { av_log(arpeggio, AV_LOG_ERROR, "Cannot allocate metadata tag %s!\n", metadata_tag); return res; } } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if (entries != arpeggio->entries) { av_log(arpeggio, AV_LOG_ERROR, "Number of attached arpeggio entries does not match actual reads (expected: %d, got: %d)!\n", arpeggio->entries, entries); return AVERROR_INVALIDDATA; } return 0; } static int open_arpg_arpe(AVFormatContext *s, AVSequencerArpeggio *arpeggio, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerArpeggioData *data; uint32_t iff_size = 4; uint16_t ticks = 0; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_ARPE: if (ticks) { if ((res = avseq_arpeggio_data_open(arpeggio, arpeggio->entries + 1)) < 0) { return res; } } ticks = arpeggio->entries; data = &(arpeggio->data[ticks - 1]); data->tone = get_byte(pb); data->transpose = get_byte(pb); data->instrument = get_be16(pb); data->command[0] = get_byte(pb); data->command[1] = get_byte(pb); data->command[2] = get_byte(pb); data->command[3] = get_byte(pb); data->data[0] = get_be16(pb); data->data[1] = get_be16(pb); data->data[2] = get_be16(pb); data->data[3] = get_be16(pb); break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if (!ticks) { av_log(arpeggio, AV_LOG_ERROR, "Attached arpeggio structure entries do not match actual reads!\n"); return AVERROR_INVALIDDATA; } return 0; } #endif static const char *nna_name[] = {"Cut", "Con", "Off", "Fde"}; static const char *note_name[] = {"--", "C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}; static const char *spec_note_name[] = {"END", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "-\\-", "-|-", "===", "^^-", "^^^"}; static int iff_read_packet(AVFormatContext *s, AVPacket *pkt) { IffDemuxContext *iff = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st = s->streams[0]; int ret; if(iff->sent_bytes >= iff->body_size) return AVERROR_EOF; #if CONFIG_AVSEQUENCER if (iff->avctx) { int32_t row; uint16_t channel; const AVSequencerPlayerGlobals *const player_globals = iff->avctx->player_globals; const AVSequencerPlayerHostChannel *player_host_channel = iff->avctx->player_host_channel; const AVSequencerPlayerChannel *player_channel; char *buf; AVMixerData *mixer_data = iff->avctx->player_mixer_data; const int size = st->codec->channels * mixer_data->mix_buf_size << 2; avseq_mixer_do_mix(mixer_data, NULL); if (!(buf = av_malloc(16 * iff->avctx->player_song->channels))) { avsequencer_destroy(iff->avctx); iff->avctx = NULL; av_log(s, AV_LOG_ERROR, "Cannot allocate pattern display buffer!\n"); return AVERROR(ENOMEM); } snprintf(buf, 16 * iff->avctx->player_song->channels, " Row "); for (channel = 0; channel < iff->avctx->player_song->channels; ++channel) { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%3d ", channel + 1); } av_log(NULL, AV_LOG_INFO, "\n\n\n%s \n", buf); for (row = FFMAX(FFMIN((int32_t) player_host_channel->row - 11, (int32_t) player_host_channel->max_row - 24), 0); row <= FFMIN(FFMAX((int32_t) player_host_channel->row + 12, 23), (int32_t) player_host_channel->max_row - 1); ++row) { if (row == player_host_channel->row) snprintf(buf, 16 * iff->avctx->player_song->channels, ">%04X ", row); else snprintf(buf, 16 * iff->avctx->player_song->channels, " %04X ", row); channel = 0; do { if (player_host_channel->track) { AVSequencerTrackRow *track_row = player_host_channel->track->data + row; switch (track_row->note) { case AVSEQ_TRACK_DATA_NOTE_NONE: if (track_row->effects) { AVSequencerTrackEffect *fx = track_row->effects_data[0]; if (fx->command || fx->data) snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%02X%02X", fx->command, fx->data >> 8 ? fx->data >> 8 : fx->data & 0xFF); else snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } else { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } break; case AVSEQ_TRACK_DATA_NOTE_C: case AVSEQ_TRACK_DATA_NOTE_C_SHARP: case AVSEQ_TRACK_DATA_NOTE_D: case AVSEQ_TRACK_DATA_NOTE_D_SHARP: case AVSEQ_TRACK_DATA_NOTE_E: case AVSEQ_TRACK_DATA_NOTE_F: case AVSEQ_TRACK_DATA_NOTE_F_SHARP: case AVSEQ_TRACK_DATA_NOTE_G: case AVSEQ_TRACK_DATA_NOTE_G_SHARP: case AVSEQ_TRACK_DATA_NOTE_A: case AVSEQ_TRACK_DATA_NOTE_A_SHARP: case AVSEQ_TRACK_DATA_NOTE_B: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%2s%1d ", note_name[track_row->note], track_row->octave); break; case AVSEQ_TRACK_DATA_NOTE_KILL: case AVSEQ_TRACK_DATA_NOTE_OFF: case AVSEQ_TRACK_DATA_NOTE_KEYOFF: case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY: case AVSEQ_TRACK_DATA_NOTE_FADE: case AVSEQ_TRACK_DATA_NOTE_END: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%3s ", spec_note_name[(uint8_t) track_row->note - 0xF0]); break; default: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "??? "); break; } } else { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } player_host_channel++; } while (++channel < iff->avctx->player_song->channels); av_log(NULL, AV_LOG_INFO, "%s\n", buf); player_host_channel = iff->avctx->player_host_channel; } av_log(NULL, AV_LOG_INFO, "\nVch Frequency Position Ch Row Tick Tm FVl Vl CV SV VE Fade Pn PE NNA Tot\n"); player_channel = iff->avctx->player_channel; channel = 0; do { player_host_channel = iff->avctx->player_host_channel + player_channel->host_channel; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND) av_log(NULL, AV_LOG_INFO, "%3d %9d %8d %3d %04X %04X %02X %3d %02X %02X %02X %02X %04X Su %02X %s %3d\n", channel + 1, player_channel->mixer.rate, player_channel->mixer.pos, player_channel->host_channel, player_host_channel->row, player_host_channel->tempo_counter, player_host_channel->tempo, player_channel->final_volume, player_channel->volume, player_host_channel->track_volume, player_channel->instr_volume / 255, (uint16_t) player_channel->vol_env.value / 256, player_channel->fade_out_count, (player_channel->pan_env.value >> 8) + 128, nna_name[player_host_channel->nna], player_host_channel->virtual_channels); else av_log(NULL, AV_LOG_INFO, "%3d %9d %8d %3d %04X %04X %02X %3d %02X %02X %02X %02X %04X %02X %02X %s %3d\n", channel + 1, player_channel->mixer.rate, player_channel->mixer.pos, player_channel->host_channel, player_host_channel->row, player_host_channel->tempo_counter, player_host_channel->tempo, player_channel->final_volume, player_channel->volume, player_host_channel->track_volume, player_channel->instr_volume / 255, (uint16_t) player_channel->vol_env.value / 256, player_channel->fade_out_count, (uint8_t) player_channel->final_panning, (player_channel->pan_env.value >> 8) + 128, nna_name[player_host_channel->nna], player_host_channel->virtual_channels); } else { av_log(NULL, AV_LOG_INFO, "%3d --- 0\n", channel + 1); } player_channel++; } while (++channel < FFMIN(iff->avctx->player_module->channels, 24)); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING) { snprintf(buf, 16, "%d (%d)", player_globals->channels, player_globals->max_channels); if (player_globals->speed_mul < 2 && player_globals->speed_div < 2) av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d (SPD)\n", buf, player_globals->spd_speed); else av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d (%d/%d SPD)\n", buf, player_globals->spd_speed, player_globals->speed_mul, player_globals->speed_div); } else { snprintf(buf, 16, "%d (%d)", player_globals->channels, player_globals->max_channels); if (player_globals->speed_mul < 2 && player_globals->speed_div < 2) av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d/%d (BpM)\n", buf, player_globals->bpm_speed, player_globals->bpm_tempo); else av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d/%d (%d/%d BpM)\n", buf, player_globals->bpm_speed, player_globals->bpm_tempo, player_globals->speed_mul, player_globals->speed_div); } av_free(buf); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND) av_log(NULL, AV_LOG_INFO, " Global Volume: %3d Global Panning: Su\n", player_globals->global_volume); else av_log(NULL, AV_LOG_INFO, " Global Volume: %3d Global Panning: %02X\n", player_globals->global_volume, (uint8_t) player_globals->global_panning); player_host_channel = iff->avctx->player_host_channel; av_log(NULL, AV_LOG_INFO, "\033[%dA\n", FFMIN(iff->avctx->player_module->channels, 24) + 33); if ((ret = av_new_packet(pkt, size)) < 0) { avsequencer_destroy(iff->avctx); iff->avctx = NULL; av_log(s, AV_LOG_ERROR, "Cannot allocate packet!\n"); return ret; } memcpy(pkt->data, mixer_data->mix_buf, size); iff->sent_bytes += size; pkt->duration = mixer_data->mix_buf_size; st->time_base = (AVRational) {1, st->codec->sample_rate}; pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = 0; pkt->pts = iff->audio_frame_count; iff->audio_frame_count += mixer_data->mix_buf_size; return size; } #endif if(st->codec->channels == 2) { uint8_t sample_buffer[PACKET_SIZE]; ret = get_buffer(pb, sample_buffer, PACKET_SIZE); if(av_new_packet(pkt, PACKET_SIZE) < 0) { av_log(s, AV_LOG_ERROR, "iff: cannot allocate packet \n"); return AVERROR(ENOMEM); } interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ret = av_get_packet(pb, pkt, iff->body_size); } else { ret = av_get_packet(pb, pkt, PACKET_SIZE); } if(iff->sent_bytes == 0) pkt->flags |= AV_PKT_FLAG_KEY; if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { iff->sent_bytes += PACKET_SIZE; } else { iff->sent_bytes = iff->body_size; } pkt->stream_index = 0; if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { pkt->pts = iff->audio_frame_count; iff->audio_frame_count += ret / st->codec->channels; } return ret; } static int iff_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[0]; #if CONFIG_AVSEQUENCER IffDemuxContext *iff; AVMixerContext *mixctx; AVMixerData *mixer_data; #endif switch (st->codec->codec_tag) { #if CONFIG_AVSEQUENCER case ID_TCM1: iff = s->priv_data; if (!iff->avctx) return -1; if ((mixctx = avseq_mixer_get_by_name("Null mixer"))) { AVSequencerPlayerGlobals *player_globals; AVMixerData *mixer_data; AVMixerData *old_mixer_data = iff->avctx->player_mixer_data; uint32_t tempo; uint16_t channel; int res, size; if (timestamp < 0) timestamp = 0; iff->avctx->player_mixer_data = NULL; avseq_module_stop(iff->avctx, 0); if (flags & AVSEEK_FLAG_BACKWARD) { if ((res = avseq_song_reset(iff->avctx, iff->avctx->player_song)) < 0) { iff->avctx->player_mixer_data = old_mixer_data; avsequencer_destroy(iff->avctx); iff->avctx = NULL; return res; } iff->sent_bytes = 0; iff->audio_frame_count = 0; } player_globals = iff->avctx->player_globals; if ((res = avseq_module_play(iff->avctx, mixctx, iff->avctx->player_module, iff->avctx->player_song, iff->args, iff->opaque, (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) ? 0 : 1)) < 0) { avseq_module_stop(iff->avctx, 0); iff->avctx->player_mixer_data = old_mixer_data; avsequencer_destroy(iff->avctx); iff->avctx = NULL; return res; } mixer_data = iff->avctx->player_mixer_data; tempo = avseq_song_calc_speed(iff->avctx, iff->avctx->player_song); mixer_data->flags |= AVSEQ_MIXER_DATA_FLAG_MIXING; avseq_mixer_set_rate(mixer_data, st->codec->sample_rate, st->codec->channels); avseq_mixer_set_tempo(mixer_data, tempo); avseq_mixer_set_volume(mixer_data, 0, 0, 0, iff->avctx->player_module->channels); size = st->codec->channels * mixer_data->mix_buf_size << 2; timestamp = (timestamp * AV_TIME_BASE * st->time_base.num) / st->time_base.den; if (flags & AVSEEK_FLAG_BACKWARD) { timestamp += player_globals->play_time; } else { channel = iff->avctx->player_module->channels - 1; do { AVMixerChannel mixer_channel_current; AVMixerChannel mixer_channel_next; avseq_mixer_get_both_channels(old_mixer_data, &mixer_channel_current, &mixer_channel_next, channel); avseq_mixer_set_both_channels(mixer_data, &mixer_channel_current, &mixer_channel_next, channel); } while (channel--); } while (player_globals->play_time < timestamp) { avseq_mixer_do_mix(mixer_data, NULL); iff->sent_bytes += size; iff->audio_frame_count += mixer_data->mix_buf_size; } channel = iff->avctx->player_module->channels - 1; do { AVMixerChannel mixer_channel_current; AVMixerChannel mixer_channel_next; avseq_mixer_get_both_channels(mixer_data, &mixer_channel_current, &mixer_channel_next, channel); avseq_mixer_reset_channel(old_mixer_data, channel); avseq_mixer_set_both_channels(old_mixer_data, &mixer_channel_current, &mixer_channel_next, channel); } while (channel--); avseq_module_stop(iff->avctx, 0); + avseq_mixer_set_tempo(old_mixer_data, mixer_data->tempo); iff->avctx->player_mixer_data = old_mixer_data; } else { mixer_data = iff->avctx->player_mixer_data; mixctx = mixer_data->mixctx; } break; #endif default: break; } if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) return pcm_read_seek(s, stream_index, timestamp, flags); return -1; } AVInputFormat iff_demuxer = { "IFF", NULL_IF_CONFIG_SMALL("IFF format"), sizeof(IffDemuxContext), iff_probe, iff_read_header, iff_read_packet, NULL, iff_read_seek, .flags = AVSEEK_FLAG_ANY }; diff --git a/libavsequencer/player.c b/libavsequencer/player.c index e4219cf..ad14eb4 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -3748,1400 +3748,1541 @@ EXECUTE_EFFECT(panning_slide_to) panning_slide_to_value = player_host_channel->panning_slide_to; player_host_channel->panning_slide_to = panning_slide_to_value; player_host_channel->panning_slide_to_slide &= 0x00FF; player_host_channel->panning_slide_to_slide += panning_slide_to_value << 8; panning_slide_to_panning = data_word >> 8; if (panning_slide_to_panning && (panning_slide_to_panning < 0xFF)) { player_host_channel->panning_slide_to_panning = panning_slide_to_panning; } else if (panning_slide_to_panning && (player_channel->host_channel == channel)) { const uint16_t panning_slide_target = ((uint8_t) panning_slide_to_panning << 8) + player_host_channel->panning_slide_to_sub_panning; uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < panning_slide_target) { do_panning_slide_right(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target <= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } else { do_panning_slide(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target >= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } } } EXECUTE_EFFECT(pannolo) { int16_t pannolo_slide_value; uint8_t pannolo_rate; int16_t pannolo_depth; if (!(pannolo_rate = (data_word >> 8))) pannolo_rate = player_host_channel->pannolo_rate; player_host_channel->pannolo_rate = pannolo_rate; if (!(pannolo_depth = (int8_t) data_word)) pannolo_depth = player_host_channel->pannolo_depth; player_host_channel->pannolo_depth = pannolo_depth; pannolo_slide_value = (-(int32_t) pannolo_depth * run_envelope(avctx, &player_host_channel->pannolo_env, pannolo_rate, 0)) >> 7; if (player_channel->host_channel == channel) { const int16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_host_channel->pannolo_slide; if ((int16_t) (pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_host_channel->pannolo_slide -= panning - pannolo_slide_value; player_host_channel->track_note_panning = player_host_channel->track_panning = panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_channel->sub_panning; } } EXECUTE_EFFECT(set_track_panning) { player_host_channel->channel_panning = data_word >> 8; player_host_channel->channel_sub_panning = data_word; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; } EXECUTE_EFFECT(track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->track_pan_slide_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->fine_trk_pan_sld_right; v8 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_pan_slide_left = data_word; player_host_channel->track_pan_slide_right = v3; player_host_channel->fine_trk_pan_sld_left = v4; player_host_channel->fine_trk_pan_sld_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->track_pan_slide_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v3 = player_host_channel->fine_trk_pan_sld_left; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = data_word; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = data_word; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v3 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(track_panning_slide_to) { uint8_t track_pan_slide_to, track_panning_slide_to_panning; if (!(track_pan_slide_to = (uint8_t) data_word)) track_pan_slide_to = player_host_channel->track_pan_slide_to; player_host_channel->track_pan_slide_to = track_pan_slide_to; player_host_channel->track_pan_slide_to_slide &= 0x00FF; player_host_channel->track_pan_slide_to_slide += track_pan_slide_to << 8; track_panning_slide_to_panning = data_word >> 8; if (track_panning_slide_to_panning && (track_panning_slide_to_panning < 0xFF)) { player_host_channel->track_pan_slide_to_panning = track_panning_slide_to_panning; } else if (track_panning_slide_to_panning) { const uint16_t track_panning_slide_to_target = ((uint8_t) track_panning_slide_to_panning << 8) + player_host_channel->track_pan_slide_to_sub_panning; uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning < track_panning_slide_to_target) { do_track_panning_slide_right(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target <= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } else { do_track_panning_slide(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target >= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } } } EXECUTE_EFFECT(track_pannolo) { int16_t track_pannolo_slide_value; uint8_t track_pannolo_rate; int16_t track_pannolo_depth; uint16_t track_panning; if (!(track_pannolo_rate = (data_word >> 8))) track_pannolo_rate = player_host_channel->track_pan_rate; player_host_channel->track_pan_rate = track_pannolo_rate; if (!(track_pannolo_depth = (int8_t) data_word)) track_pannolo_depth = player_host_channel->track_pan_depth; player_host_channel->track_pan_depth = track_pannolo_depth; track_pannolo_slide_value = (-(int32_t) track_pannolo_depth * run_envelope(avctx, &player_host_channel->track_pan_env, track_pannolo_rate, 0)) >> 7; track_panning = (uint8_t) player_host_channel->track_panning; track_pannolo_slide_value -= player_host_channel->track_pan_slide; if ((int16_t) (track_pannolo_slide_value += track_panning) < 0) track_pannolo_slide_value = 0; if (track_pannolo_slide_value > 255) track_pannolo_slide_value = 255; player_host_channel->track_panning = track_pannolo_slide_value; player_host_channel->track_pan_slide -= track_panning - track_pannolo_slide_value; } EXECUTE_EFFECT(set_tempo) { if (!(player_host_channel->tempo = data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(set_relative_tempo) { if (!(player_host_channel->tempo += data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(pattern_break) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = data_word; } } EXECUTE_EFFECT(position_jump) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { AVSequencerOrderData *order_data = NULL; if (data_word--) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; if ((data_word < order_list->orders) && order_list->order_data[data_word]) order_data = order_list->order_data[data_word]; } player_host_channel->order = order_data; pattern_break(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_PATT_BREAK, 0); } } EXECUTE_EFFECT(relative_position_jump) { if (!data_word) data_word = player_host_channel->pos_jump; if ((player_host_channel->pos_jump = data_word)) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; AVSequencerOrderData *order_data = player_host_channel->order; uint32_t ord = -1; while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; ord++; } ord += (int32_t) data_word; if (ord > 0xFFFF) ord = 0; position_jump(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_POS_JUMP, (uint16_t) ord); } } EXECUTE_EFFECT(change_pattern) { player_host_channel->chg_pattern = data_word; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; } EXECUTE_EFFECT(reverse_pattern_play) { if (!data_word) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else if (data_word & 0x8000) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; } EXECUTE_EFFECT(pattern_delay) { player_host_channel->pattern_delay = data_word; } EXECUTE_EFFECT(fine_pattern_delay) { player_host_channel->fine_pattern_delay = data_word; } EXECUTE_EFFECT(pattern_loop) { const AVSequencerSong *const song = avctx->player_song; uint16_t *loop_stack_ptr; uint16_t loop_length = player_host_channel->pattern_loop_depth; loop_stack_ptr = (uint16_t *) avctx->player_globals->loop_stack + (((song->loop_stack_size * channel) * sizeof (uint16_t[2])) + (loop_length * sizeof(uint16_t[2]))); if (data_word) { if (data_word == *loop_stack_ptr) { *loop_stack_ptr = 0; if (loop_length--) player_host_channel->pattern_loop_depth = loop_length; else player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; } else { (*loop_stack_ptr++)++; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; player_host_channel->break_row = *loop_stack_ptr; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } } else if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; *loop_stack_ptr++ = 0; *loop_stack_ptr = player_host_channel->row; if (++loop_length != song->loop_stack_size) player_host_channel->pattern_loop_depth = loop_length; } } EXECUTE_EFFECT(gosub) { // TODO: Implement GoSub effect } EXECUTE_EFFECT(gosub_return) { // TODO: Implement return effect } EXECUTE_EFFECT(channel_sync) { // TODO: Implement channel synchronizattion effect } EXECUTE_EFFECT(set_sub_slides) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t sub_slide_flags; if (!(sub_slide_flags = (data_word >> 8))) sub_slide_flags = player_host_channel->sub_slide_bits; if (sub_slide_flags & 0x01) player_host_channel->volume_slide_to_volume = data_word; if (sub_slide_flags & 0x02) player_host_channel->track_vol_slide_to_sub_volume = data_word; if (sub_slide_flags & 0x04) player_globals->global_volume_sl_to_sub_volume = data_word; if (sub_slide_flags & 0x08) player_host_channel->panning_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x10) player_host_channel->track_pan_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x20) player_globals->global_pan_slide_to_sub_panning = data_word; } EXECUTE_EFFECT(sample_offset_high) { player_host_channel->smp_offset_hi = data_word; } EXECUTE_EFFECT(sample_offset_low) { if (player_channel->host_channel == channel) { uint32_t sample_offset = (player_host_channel->smp_offset_hi << 16) + data_word; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL)) { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SAMPLE_OFFSET) { const AVSequencerSample *const sample = player_channel->sample; if (sample_offset >= sample->samples) return; } player_channel->mixer.pos = 0; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t repeat_end = player_channel->mixer.repeat_start + player_channel->mixer.repeat_length; if (repeat_end < sample_offset) sample_offset = repeat_end; } } player_channel->mixer.pos += sample_offset; } } EXECUTE_EFFECT(set_hold) { // TODO: Implement set hold effect } EXECUTE_EFFECT(set_decay) { // TODO: Implement set decay effect } EXECUTE_EFFECT(set_transpose) { // TODO: Implement set transpose effect } EXECUTE_EFFECT(instrument_ctrl) { - // TODO: Implement instrument control effect + const uint32_t flags = player_host_channel->flags; + uint8_t off_bits = data_word >> 8; + uint8_t on_bits = data_word; + uint8_t xor_bits = off_bits & on_bits; + + if (xor_bits & 0x01) + player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; + else if (off_bits & 0x01) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; + else if (on_bits & 0x01) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; + + if (flags != player_host_channel->flags) { + const AVSequencerInstrument *instrument; + const AVSequencerSample *const sample = player_host_channel->sample; + + if (sample) { + uint32_t panning, seed; + + panning = (uint8_t) player_host_channel->track_note_panning; + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = sample->panning; + player_channel->sub_panning = sample->sub_panning; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->track_note_panning = panning; + player_host_channel->track_note_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } else { + player_channel->panning = player_host_channel->track_panning; + player_channel->sub_panning = player_host_channel->track_sub_panning; + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + } + + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if ((instrument = player_channel->instrument)) { + uint32_t panning_swing; + int32_t panning_separation; + + if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = instrument->default_panning; + player_channel->sub_panning = instrument->default_sub_pan; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = player_channel->panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } + + panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; + panning_swing = (player_channel->panning_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + panning_swing = ((uint64_t) seed * panning_swing) >> 32; + panning_swing -= instrument->panning_swing; + panning += panning_swing; + + if ((int32_t) (panning += panning_separation) < 0) + panning = 0; + + if (panning > 255) + panning = 255; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) + player_host_channel->track_panning = panning; + else + player_channel->panning = panning; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { + player_host_channel->track_panning = panning; + player_channel->panning = panning; + } + } + } + } + + if (xor_bits & 0x02) + player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; + else if (off_bits & 0x02) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; + else if (on_bits & 0x02) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; + + if (xor_bits & 0x08) + player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; + else if (off_bits & 0x08) + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; + else if (on_bits & 0x08) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; + + if (xor_bits & 0x10) + player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; + else if (off_bits & 0x10) + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; + else if (on_bits & 0x10) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; + + if (xor_bits & 0x20) + player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; + else if (off_bits & 0x20) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; + else if (on_bits & 0x20) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL; + + if (xor_bits & 0x80) + player_channel->flags ^= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; + else if (off_bits & 0x80) + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; + else if (on_bits & 0x80) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; } EXECUTE_EFFECT(instrument_change) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample; AVMixerData *mixer; uint32_t volume, volume_swing, panning, abs_volume_swing, seed; switch (data_word >> 12) { case 0x0 : sample = player_host_channel->sample; volume = player_channel->instr_volume; player_channel->global_instr_volume = data_word; if (sample && (instrument = player_host_channel->instrument)) { volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else if (sample) { volume = player_channel->global_instr_volume * 255; } player_channel->instr_volume = volume; break; case 0x1 : sample = player_host_channel->sample; volume = player_channel->instr_volume; volume_swing = data_word & 0xFFF; if (sample && (instrument = player_host_channel->instrument)) { volume = sample->global_volume * player_channel->global_instr_volume; volume_swing = (volume * volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else if (sample) { volume = sample->global_volume * 255; volume_swing = (volume * instrument->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } player_channel->instr_volume = volume; player_channel->volume_swing = volume_swing; break; case 0x2 : if ((sample = player_host_channel->sample)) { panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; - + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; - + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if ((instrument = player_channel->instrument)) { uint32_t panning_swing; int32_t panning_separation; player_channel->panning_swing = panning_swing = data_word & 0xFFF; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; - if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; - player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); - + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } } } break; case 0x3 : player_channel->pitch_swing = (((uint32_t) data_word & 0xFFF) << 16) / 100; break; case 0x4 : player_channel->fade_out = data_word << 4; break; case 0x5 : if (data_word & 0xFFF) player_channel->fade_out_count = data_word << 4; else player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case 0x6 : switch ((data_word >> 8) & 0xF) { case 0x0 : player_channel->auto_vibrato_sweep = data_word & 0xFF; break; case 0x1 : player_channel->auto_vibrato_depth = data_word; break; case 0x2 : player_channel->auto_vibrato_rate = data_word; break; case 0x4 : player_channel->auto_tremolo_sweep = data_word & 0xFF; break; case 0x5 : player_channel->auto_tremolo_depth = data_word; break; case 0x6 : player_channel->auto_tremolo_rate = data_word; break; case 0x8 : player_channel->auto_pannolo_sweep = data_word & 0xFF; break; case 0x9 : player_channel->auto_pannolo_sweep = data_word; break; case 0xA : player_channel->auto_pannolo_sweep = data_word; break; } break; case 0x7 : if ((sample = player_host_channel->sample)) { panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if ((instrument = player_channel->instrument)) { uint32_t panning_swing; int32_t panning_separation; player_channel->pitch_pan_separation = data_word & 0xFFF; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; - if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; - player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } } } break; case 0x8 : if ((sample = player_host_channel->sample)) { panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if ((instrument = player_channel->instrument)) { uint32_t panning_swing; int32_t panning_separation; player_channel->pitch_pan_center = data_word; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; - if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; - player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } } } break; case 0x9 : if ((data_word & 0xFFF) <= 2) player_channel->dca = data_word; break; case 0xA : mixer = avctx->player_mixer_data; player_channel->mixer.filter_cutoff = data_word & 0xFFF; if (mixer->mixctx->set_channel_filter) mixer->mixctx->set_channel_filter(mixer, &player_channel->mixer, player_host_channel->virtual_channel); break; case 0xB : mixer = avctx->player_mixer_data; player_channel->mixer.filter_damping = data_word & 0xFFF; if (mixer->mixctx->set_channel_filter) mixer->mixctx->set_channel_filter(mixer, &player_channel->mixer, player_host_channel->virtual_channel); break; case 0xC : player_channel->note_swing = data_word; break; } } EXECUTE_EFFECT(set_synth_value) { uint8_t synth_ctrl_count = player_host_channel->synth_ctrl_count; const uint16_t synth_ctrl_change = player_host_channel->synth_ctrl_change & 0x7F; player_host_channel->synth_ctrl = data_word; do { switch (synth_ctrl_change) { case 0x00 : case 0x01 : case 0x02 : case 0x03 : player_channel->entry_pos[synth_ctrl_change & 3] = data_word; break; case 0x04 : case 0x05 : case 0x06 : case 0x07 : player_channel->sustain_pos[synth_ctrl_change & 3] = data_word; break; case 0x08 : case 0x09 : case 0x0A : case 0x0B : player_channel->nna_pos[synth_ctrl_change & 3] = data_word; break; case 0x0C : case 0x0D : case 0x0E : case 0x0F : player_channel->dna_pos[synth_ctrl_change & 3] = data_word; break; case 0x10 : case 0x11 : case 0x12 : case 0x13 : case 0x14 : case 0x15 : case 0x16 : case 0x17 : case 0x18 : case 0x19 : case 0x1A : case 0x1B : case 0x1C : case 0x1D : case 0x1E : case 0x1F : player_channel->variable[synth_ctrl_change & 0xF] = data_word; break; case 0x20 : case 0x21 : case 0x22 : case 0x23 : player_channel->cond_var[synth_ctrl_change & 3] = data_word; break; case 0x24 : if (data_word < player_channel->synth->waveforms) player_channel->sample_waveform = player_channel->waveform_list[data_word]; break; case 0x25 : if (data_word < player_channel->synth->waveforms) player_channel->vibrato_waveform = player_channel->waveform_list[data_word]; break; case 0x26 : if (data_word < player_channel->synth->waveforms) player_channel->tremolo_waveform = player_channel->waveform_list[data_word]; break; case 0x27 : if (data_word < player_channel->synth->waveforms) player_channel->pannolo_waveform = player_channel->waveform_list[data_word]; break; case 0x28 : if (data_word < player_channel->synth->waveforms) player_channel->arpeggio_waveform = player_channel->waveform_list[data_word]; break; } } while (synth_ctrl_count--); } EXECUTE_EFFECT(synth_ctrl) { player_host_channel->synth_ctrl_count = data_word >> 8; player_host_channel->synth_ctrl_change = data_word; if (data_word & 0x80) set_synth_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_SYN_VAL, player_host_channel->synth_ctrl); } static const void *envelope_ctrl_type_lut[] = { use_volume_envelope, use_panning_envelope, use_slide_envelope, use_vibrato_envelope, use_tremolo_envelope, use_pannolo_envelope, use_channolo_envelope, use_spenolo_envelope, use_auto_vibrato_envelope, use_auto_tremolo_envelope, use_auto_pannolo_envelope, use_track_tremolo_envelope, use_track_pannolo_envelope, use_global_tremolo_envelope, use_global_pannolo_envelope, use_arpeggio_envelope, use_resonance_envelope }; EXECUTE_EFFECT(set_envelope_value) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); player_host_channel->env_ctrl = data_word; envelope_get_kind = envelope_ctrl_type_lut[player_host_channel->env_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (player_host_channel->env_ctrl_change) { case 0x00 : if ((data_word < module->envelopes) && ((instrument_envelope = module->envelope_list[data_word]))) envelope->envelope = instrument_envelope; else envelope->envelope = NULL; break; case 0x04 : envelope->pos = data_word; break; case 0x14 : if ((instrument_envelope = envelope->envelope)) { if (++data_word > instrument_envelope->nodes) data_word = instrument_envelope->nodes; envelope->pos = instrument_envelope->node_points[data_word - 1]; } break; case 0x05 : envelope->tempo = data_word; break; case 0x15 : envelope->tempo += data_word; break; case 0x25 : envelope->tempo_count = data_word; break; case 0x06 : envelope->sustain_start = data_word; break; case 0x07 : envelope->sustain_end = data_word; break; case 0x08 : envelope->sustain_count = data_word; break; case 0x09 : envelope->sustain_counted = data_word; break; case 0x0A : envelope->loop_start = data_word; break; case 0x1A : envelope->start = data_word; break; case 0x0B : envelope->loop_end = data_word; break; case 0x1B : envelope->end = data_word; break; case 0x0C : envelope->loop_count = data_word; break; case 0x0D : envelope->loop_counted = data_word; break; case 0x0E : envelope->value_min = data_word; break; case 0x0F : envelope->value_max = data_word; break; } } EXECUTE_EFFECT(envelope_ctrl) { const uint8_t envelope_ctrl_kind = (data_word >> 8) & 0x7F; if (envelope_ctrl_kind <= 0x10) { const uint8_t envelope_ctrl_type = data_word; player_host_channel->env_ctrl_kind = envelope_ctrl_kind; if (envelope_ctrl_type <= 0x32) { const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); envelope_get_kind = envelope_ctrl_type_lut[envelope_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (envelope_ctrl_type) { case 0x10 : if ((instrument_envelope = envelope->envelope)) { envelope->tempo = instrument_envelope->tempo; envelope->sustain_counted = 0; envelope->loop_counted = 0; envelope->tempo_count = 0; envelope->sustain_start = instrument_envelope->sustain_start; envelope->sustain_end = instrument_envelope->sustain_end; envelope->sustain_count = instrument_envelope->sustain_count; envelope->loop_start = instrument_envelope->loop_start; envelope->loop_end = instrument_envelope->loop_end; envelope->loop_count = instrument_envelope->loop_count; envelope->value_min = instrument_envelope->value_min; envelope->value_max = instrument_envelope->value_max; envelope->rep_flags = instrument_envelope->flags; set_envelope(player_channel, envelope, envelope->pos); } break; case 0x01 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; break; case 0x11 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; break; case 0x02 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x12 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x22 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x32 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x03 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; case 0x13 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; default : player_host_channel->env_ctrl_change = envelope_ctrl_type; if (data_word & 0x8000) set_envelope_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_ENV_VAL, player_host_channel->env_ctrl); break; } } } } EXECUTE_EFFECT(nna_ctrl) { const uint8_t nna_ctrl_type = data_word >> 8; uint8_t nna_ctrl_action = data_word; switch (nna_ctrl_type) { case 0x00 : switch (nna_ctrl_action) { case 0x00 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; break; case 0x01 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF; break; case 0x02 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CONTINUE; break; case 0x03 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE; break; } break; case 0x11 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct |= nna_ctrl_action; break; case 0x01 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct &= ~nna_ctrl_action; break; case 0x02 : player_host_channel->dna = nna_ctrl_action; break; } } EXECUTE_EFFECT(loop_ctrl) { // TODO: Implement loop control effect } EXECUTE_EFFECT(set_speed) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_value, speed_min_value, speed_max_value; uint8_t speed_type = data_word >> 12; if ((speed_ptr = get_speed_address(avctx, speed_type, &speed_min_value, &speed_max_value))) { if (!(speed_value = (data_word & 0xFFF))) { if ((data_word & 0x7000) == 0x7000) speed_value = (player_globals->speed_mul << 8U) + player_globals->speed_div; else speed_value = *speed_ptr; } speed_val_ok(avctx, speed_ptr, speed_value, speed_type, speed_min_value, speed_max_value); } } EXECUTE_EFFECT(speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_globals->speed_slide_faster; do_speed_slide(avctx, data_word); track = player_host_channel->track; v3 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_fast; v5 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->speed_slide_faster = data_word; player_globals->speed_slide_slower = v3; player_globals->fine_speed_slide_fast = v4; player_globals->fine_speed_slide_slow = v5; } EXECUTE_EFFECT(speed_slide_slower) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_globals->speed_slide_slower; do_speed_slide_slower(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v3 = player_globals->fine_speed_slide_fast; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = data_word; player_globals->fine_speed_slide_fast = v3; player_globals->fine_speed_slide_slow = v4; } EXECUTE_EFFECT(fine_speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_globals->fine_speed_slide_fast; do_speed_slide(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v1 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; @@ -8448,1571 +8589,1579 @@ loop_to_row: if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) row = last_row - row; } player_host_channel->row = row; if ((int) ((player_host_channel->track->data) + row)->note == AVSEQ_TRACK_DATA_NOTE_END) { if (++counted) goto get_new_pattern; goto disable_channel; } } } static const AVSequencerPlayerEffects fx_lut[128] = { {arpeggio, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {fine_tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {note_slide, NULL, check_note_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {fine_vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {do_key_off, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {hold_delay, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_fade, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_cut, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_delay, preset_note_delay, NULL, 0x00, 0x00, 0x0000}, {tremor, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_retrigger, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {multi_retrigger_note, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {extended_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {invert_loop, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {exec_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {stop_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {volume_slide_up, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {volume_slide_down, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_volume_slide_up, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {fine_volume_slide_down, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, 0x00, 0x01, 0x0000}, {set_track_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {track_volume_slide_up, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_volume_slide_down, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_volume_slide_up, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {fine_track_volume_slide_down, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {track_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {panning_slide_left, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {panning_slide_right, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_panning_slide_left, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {fine_panning_slide_right, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_track_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {track_panning_slide_left, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_panning_slide_right, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_panning_slide_left, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {fine_track_panning_slide_right, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {track_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {set_relative_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_break, NULL, NULL, 0x00, 0x02, 0x0000}, {position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {relative_position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {change_pattern, NULL, NULL, 0x00, 0x02, 0x0000}, {reverse_pattern_play, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {fine_pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_loop, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub_return, NULL, NULL, 0x00, 0x02, 0x0000}, {channel_sync, NULL, NULL, 0x00, 0x02, 0x0000}, {set_sub_slides, NULL, NULL, 0x00, 0x02, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {sample_offset_high, NULL, NULL, 0x00, 0x01, 0x0000}, {sample_offset_low, NULL, NULL, 0x00, 0x01, 0x0000}, {set_hold, NULL, NULL, 0x00, 0x01, 0x0000}, {set_decay, NULL, NULL, 0x00, 0x01, 0x0000}, {set_transpose, preset_set_transpose, NULL, 0x00, 0x01, 0x0000}, {instrument_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {instrument_change, NULL, NULL, 0x00, 0x01, 0x0000}, {synth_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_synth_value, NULL, NULL, 0x00, 0x01, 0x0000}, {envelope_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_envelope_value, NULL, NULL, 0x00, 0x01, 0x0000}, {nna_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {loop_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_speed, NULL, NULL, 0x00, 0x00, 0x0000}, {speed_slide_faster, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {speed_slide_slower, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_speed_slide_faster, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {fine_speed_slide_slower, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {speed_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {spenolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {spenolo, NULL, NULL, 0x00, 0x00, 0x0000}, {channel_ctrl, NULL, check_channel_control, 0x00, 0x00, 0x0000}, {set_global_volume, NULL, NULL, 0x00, 0x00, 0x0000}, {global_volume_slide_up, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_volume_slide_down, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_volume_slide_up, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {fine_global_volume_slide_down, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {global_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, 0x00, 0x00, 0x0000}, {set_global_panning, NULL, NULL, 0x00, 0x00, 0x0000}, {global_panning_slide_left, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_panning_slide_right, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_panning_slide_left, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {fine_global_panning_slide_right, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {global_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {global_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_pannolo, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {user_sync, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0000} }; static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerTrack *track; const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *track_data; uint32_t fx = -1; if (!(track = player_host_channel->track)) return; track_data = track->data + player_host_channel->row; if ((track_fx = player_host_channel->effect)) { while (++fx < track_data->effects) { if (track_fx == track_data->effects_data[fx]) break; } } else if (track_data->effects) { fx = 0; track_fx = track_data->effects_data[0]; } else { track_fx = NULL; } player_host_channel->effect = track_fx; if ((fx < track_data->effects) && track_data->effects_data[fx]) { do { const int fx_byte = track_fx->command & 0x7F; if (fx_byte == AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = track_fx->data; if (player_host_channel->tempo_counter < player_host_channel->exec_fx) break; } } while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))); if (player_host_channel->effect != track_fx) { player_host_channel->effect = track_fx; AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*pre_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); const int fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; if ((pre_fx_func = effects_lut->pre_pattern_func)) pre_fx_func(avctx, player_host_channel, player_channel, channel, track_fx->data); } } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; - if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE)) + if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= player_host_channel->sample == player_channel->sample; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= player_host_channel->sample == player_channel->sample; return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; if (nna_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope * (**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope * (**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; player_channel->global_instr_volume = instrument->global_volume; player_channel->volume_swing = instrument->volume_swing; volume = sample->global_volume * player_channel->global_volume; volume_swing = (volume * player_channel->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; player_channel->auto_pannolo_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; player_channel->auto_pannolo_depth = sample->pannolo_depth; player_channel->auto_pannolo_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE; + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { - player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; - player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } + } else { + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING; } player_channel->pitch_pan_separation = instrument->pitch_pan_separation; player_channel->pitch_pan_center = instrument->pitch_pan_center; player_channel->panning_swing = instrument->panning_swing; panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; panning_swing = (player_channel->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } player_channel->note_swing = instrument->note_swing; player_channel->pitch_swing = instrument->pitch_swing; } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; new_player_channel->auto_pannolo_sweep = player_channel->auto_pannolo_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; new_player_channel->auto_pannolo_depth = player_channel->auto_pannolo_depth; new_player_channel->auto_pannolo_rate = player_channel->auto_pannolo_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; diff --git a/libavsequencer/player.h b/libavsequencer/player.h index ccb96cd..1ec4e84 100644 --- a/libavsequencer/player.h +++ b/libavsequencer/player.h @@ -1,993 +1,995 @@ /* * AVSequencer playback engine * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVSEQUENCER_PLAYER_H #define AVSEQUENCER_PLAYER_H #include "libavsequencer/instr.h" /** AVSequencerPlayerEnvelope->flags bitfield. */ enum AVSequencerPlayerEnvelopeFlags { AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD = 0x01, ///< First process envelope position then get value AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG = 0x02, ///< Do not retrigger envelope on new note playback AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM = 0x04, ///< Envelope returns randomized instead of waveform data AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY = 0x08, ///< If randomization is enabled speed is interpreted as delay AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS = 0x10, ///< Envelope is currently being played backwards AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING = 0x20, ///< Envelope is looping in either sustain or normal mode AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG = 0x40, ///< Envelope is doing ping pong style loop }; /** AVSequencerPlayerEnvelope->rep_flags bitfield. */ enum AVSequencerPlayerEnvelopeRepFlags { AVSEQ_PLAYER_ENVELOPE_REP_FLAG_LOOP = 0x01, ///< Envelope uses normal loop points AVSEQ_PLAYER_ENVELOPE_REP_FLAG_SUSTAIN = 0x02, ///< Envelope uses sustain loop points AVSEQ_PLAYER_ENVELOPE_REP_FLAG_PINGPONG = 0x04, ///< Envelope normal loop is in ping pong mode AVSEQ_PLAYER_ENVELOPE_REP_FLAG_SUSTAIN_PINGPONG = 0x08, ///< Envelope sustain loop is in ping pong mode }; /** * Player envelope structure used by playback engine for processing * envelope playback in the module replay engine. This is initialized * when a new instrument is being played from the actual instrument * envelope data and then processed each tick. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerEnvelope { /** Pointer to associated instrument envelope this envelope belongs to. */ const AVSequencerEnvelope *envelope; /** The current data value last processed by this envelope. For a volume envelope, we have a default scale range of -32767 to +32767, for panning envelopes the scale range is between -8191 to +8191. For slide, vibrato, tremolo, pannolo (and their auto versions), the scale range is between -256 to +256. */ int16_t value; /** Current envelope position in ticks (0 is first tick). */ uint16_t pos; /** Current envelope normal loop restart point. */ uint16_t start; /** Current envelope normal loop end point. */ uint16_t end; /** Current sustain loop counted tick value, i.e. how often the sustain loop points already have been triggered. */ uint16_t sustain_counted; /** Current normal loop counted tick value, i.e. how often the normal loop points already have been triggered. */ uint16_t loop_counted; /** Current envelope tempo count in ticks. */ uint16_t tempo_count; /** Current envelope tempo in ticks. */ uint16_t tempo; /** Envelope sustain loop restart point. */ uint16_t sustain_start; /** Envelope sustain loop end point. */ uint16_t sustain_end; /** Envelope sustain loop tick counter in ticks. */ uint16_t sustain_count; /** Envelope normal loop restart point. */ uint16_t loop_start; /** Envelope normal loop end point. */ uint16_t loop_end; /** Envelope normal loop tick counter in ticks. */ uint16_t loop_count; /** Randomized lowest value allowed. */ int16_t value_min; /** Randomized highest value allowed. */ int16_t value_max; /** Player envelope flags. Some sequencers allow envelopes to operate in different modes, e.g. different loop types, randomization, processing modes which have to be taken care specially in the internal playback engine. */ int8_t flags; /** Player envelope repeat flags. Some sequencers allow envelopes to operate in different repeat mode like sustain with or without ping pong mode loops, which have to be taken care specially in the internal playback engine. */ int8_t rep_flags; } AVSequencerPlayerEnvelope; /** AVSequencerPlayerGlobals->flags bitfield. */ enum AVSequencerPlayerGlobalsFlags { AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE = 0x01, ///< Song is stopped at song end instead of continuous playback AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN = 0x02, ///< Do not process order list, pattern and track data AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN = 0x04, ///< Play a single pattern only, i.e. do not process order list AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND = 0x08, ///< Initial global panning is surround panning AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END = 0x10, ///< Song end found already once (marker for one-shoot playback) AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING = 0x20, ///< Use MED compatible SPD instead of the usual BpM timing AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE = 0x40, ///< Single step mode for synth sound instruction processing (debug mode) }; /** AVSequencerPlayerGlobals->speed_type values. */ enum AVSequencerPlayerGlobalsSpeedType { AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_BPM_SPEED = 0x01, ///< Change BPM speed (beats per minute) AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_BPM_TEMPO = 0x02, ///< Change BPM tempo (rows per beat) AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_SPD_SPEED = 0x03, ///< Change SPD (MED-style timing) AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_NOM_DENOM = 0x07, ///< Apply nominator (bits 4-7) and denominator (bits 0-3) to speed AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_BPM_SPEED_NO_USE = 0x08, ///< Change BPM speed (beats per minute) but do not use it for playback AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_BPM_TEMPO_NO_USE = 0x09, ///< Change BPM tempo (rows per beat) but do not use it for playback AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_SPD_SPEED_NO_USE = 0x0A, ///< Change SPD (MED-style timing) but do not use it for playback AVSEQ_PLAYER_GLOBALS_SPEED_TYPE_NOM_DENOM_NO_USE = 0x0F, ///< Apply nominator (bits 4-7) and denominator (bits 0-3) to speed but do not use it for playback }; /** AVSequencerPlayerGlobals->play_type bitfield. */ enum AVSequencerPlayerGlobalsPlayType { AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG = 0x80, }; /** * Player global data structure used by playback engine for processing * parts of module and sub-song which have global meanings like speed, * timing mode, speed and pitch adjustments, global volume and panning * settings. This structure must be initialized before starting actual * playback. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerGlobals { /** Stack pointer for the GoSub command. This stores the return values of the order data and track row for recursive calls. */ uint16_t *gosub_stack; /** Stack pointer for the pattern loop command. This stores the loop start and loop count for recursive loops. */ uint16_t *loop_stack; /** Stack size, i.e. maximum recursion depth of GoSub command which defaults to 4. */ uint16_t gosub_stack_size; /** Stack size, i.e. maximum recursion depth of the pattern loop command, which defaults to 1 to imitate most trackers (most trackers do not even support any other value than one, i.e. the pattern loop command is not nestable). */ uint16_t loop_stack_size; /** Maximum number of host channels allocated in the stack (defaults to 16). */ uint16_t stack_channels; /** Maximum number of virtual channels, including NNA (New Note Action) background channels to be allocated and processed by the mixing engine (defaults to 64). */ uint16_t virtual_channels; /** Player envelope flags. Some sequencers allow envelopes to operate in different modes, e.g. different loop types, randomization, processing modes which have to be taken care specially in the internal playback engine. */ int8_t flags; /** Speed slide to target value, i.e. BpM or SPD value where to stop the target slide at. */ uint8_t speed_slide_to; /** Speed multiplier (nominator), a value of zero means that the nominator is ignored. */ uint8_t speed_mul; /** Speed divider (denominator), a value of zero means that the denominator is ignored. The final result of speed will always be rounded down. */ uint8_t speed_div; /** Relative speed where a value of 65536 (=0x10000) indicates 100%. This will accelate only the speed and not the pitch of the output data. */ uint32_t relative_speed; /** Relative pitch where a value of 65536 (=0x10000) indicates 100%. This will accelate only the pitch and not the speed of the output data. */ uint32_t relative_pitch; /** Current playing time of the module, in AV_TIME_BASE fractional seconds scaled by relative speed. */ uint64_t play_time; /** Current playing time fraction of the module, in AV_TIME_BASE fractional seconds scaled by relative speed. */ uint32_t play_time_frac; /** Current playing ticks of the module, in AV_TIME_BASE fractional seconds not scaled by relative speed, i.e. you can always determine the exact module position by using playing ticks instead of playing time. */ uint64_t play_tics; /** Current playing ticks fraction of the module, in AV_TIME_BASE fractional seconds not scaled by relative speed, i.e. you can always determine the exact module position by using playing ticks instead of playing time. */ uint32_t play_tics_frac; /** Current final tempo (after done all BpM / SPD calculations) in AV_TIME_BASE fractional seconds. */ uint64_t tempo; /** Current MED style SPD speed. */ uint16_t spd_speed; /** Current number of rows per beat. */ uint16_t bpm_tempo; /** Current beats per minute speed. */ uint16_t bpm_speed; /** Global volume slide to target value, i.e. the volume level where to stop the target slide at. */ uint8_t global_volume_slide_to; /** Global panning slide to target value, i.e. the panning stereo position where to stop the target slide at. */ int8_t global_pan_slide_to; /** Current global volume of current sub-song being played. All other volume related commands are scaled by this. */ uint8_t global_volume; /** Current global sub-volume of current sub-song being played. This is basically volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t global_sub_volume; /** Current global panning of current sub-song being played. All other panning related commands are scaled by this stereo separation factor. */ int8_t global_panning; /** Current global sub-panning of current sub-song being played. This is basically panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t global_sub_panning; /** Current speed slide faster value or 0 if the speed slide faster effect was not used yet during playback. */ uint16_t speed_slide_faster; /** Current speed slide slower value or 0 if the speed slide slower effect was not used yet during playback. */ uint16_t speed_slide_slower; /** Current fine speed slide faster value or 0 if the fine speed slide faster effect was not used yet during playback. */ uint16_t fine_speed_slide_fast; /** Current fine speed slide slower value or 0 if the fine speed slide slower effect was not used yet during playback. */ uint16_t fine_speed_slide_slow; /** Current speed slide to target value, i.e. BpM or SPD value where to stop the target slide at or 0 if the speed slide to effect was not used yet during playback. */ uint16_t speed_slide_to_slide; /** Current speed slide to speed, i.e. how fast the BpM or SPD value are to be changed or 0 if the speed slide to effect was not used yet during playback. */ uint16_t speed_slide_to_speed; /** Current spenolo relative slide value or zero if the spenolo effect was not used yet during playback. */ int16_t spenolo_slide; /** Current spenolo depth as passed by the effect or zero if the spenolo effect was not used yet during playback. */ int8_t spenolo_depth; /** Current spenolo rate as passed by the effect or zero if the spenolo effect was not used yet during playback. */ uint8_t spenolo_rate; /** Current global volume slide up volume level or 0 if the global volume slide up effect was not used yet during playback. */ uint16_t global_vol_slide_up; /** Current global volume slide down volume level or 0 if the global volume slide down effect was not used yet during playback. */ uint16_t global_vol_slide_down; /** Current fine global volume slide up volume level or 0 if the fine global volume slide up effect was not used yet during playback. */ uint16_t fine_global_vol_sl_up; /** Current fine global volume slide down volume level or 0 if the fine global volume slide down effect was not used yet during playback. */ uint16_t fine_global_vol_sl_down; /** Current global volume slide to target volume and sub-volume level combined or 0 if the global volume slide to effect was not used yet during playback. */ uint16_t global_volume_slide_to_slide; /** Current global volume slide to target volume or 0 if the global volume slide to effect was not used yet during playback. */ uint8_t global_volume_sl_to_volume; /** Current global volume slide to target sub-volume or 0 if the global volume slide to effect was not used yet during playback. This is basically volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t global_volume_sl_to_sub_volume; /** Current global tremolo relative slide value or zero if the global tremolo effect was not used yet during playback. */ int16_t tremolo_slide; /** Current global tremolo depth as passed by the effect or zero if the global tremolo effect was not used yet during playback. */ int8_t tremolo_depth; /** Current global tremolo rate as passed by the effect or zero if the global tremolo effect was not used yet during playback. */ uint8_t tremolo_rate; /** Current global panning slide left panning stereo position or 0 if the global panning slide left effect was not used yet during playback. */ uint16_t global_pan_slide_left; /** Current global panning slide right panning stereo position or 0 if the global panning slide right effect was not used yet during playback. */ uint16_t global_pan_slide_right; /** Current fine global panning slide left panning stereo position or 0 if the fine global panning slide left effect was not used yet during playback. */ uint16_t fine_global_pan_sl_left; /** Current fine global panning slide right panning stereo position or 0 if the fine global panning slide right effect was not used yet during playback. */ uint16_t fine_global_pan_sl_right; /** Current global panning slide to target panning and sub-panning stereo position combined or 0 if the global panning slide to effect was not used yet during playback. */ uint16_t global_pan_slide_to_slide; /** Current global panning slide to target panning or 0 if the global panning slide to effect was not used yet during playback. */ uint8_t global_pan_slide_to_panning; /** Current global panning slide to target sub-panning or 0 if the global panning slide to effect was not used yet during playback. This is basically panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t global_pan_slide_to_sub_panning; /** Current global pannolo (panbrello) relative slide value or zero if the global pannolo effect was not used yet during playback. */ int16_t pannolo_slide; /** Current global pannolo (panbrello) depth as passed by the effect or zero if the global pannolo effect was not used yet during playback. */ int8_t pannolo_depth; /** Current global pannolo (panbrello) rate as passed by the effect or zero if the global pannolo effect was not used yet during playback. */ uint8_t pannolo_rate; /** Number of virtual channels which are actively being played at once in this moment. This also includes muted channels and channels currently played at volume level zero. */ uint16_t channels; /** Number of virtual channels which have been played at maximum at once since start of playback which also includes muted channels and channels currently played at volume level 0. */ uint16_t max_channels; /** AVSequencerPlayerEnvelope pointer to spenolo envelope. */ AVSequencerPlayerEnvelope spenolo_env; /** AVSequencerPlayerEnvelope pointer to global tremolo envelope. */ AVSequencerPlayerEnvelope tremolo_env; /** AVSequencerPlayerEnvelope pointer to global pannolo envelope. */ AVSequencerPlayerEnvelope pannolo_env; /** Speed timing mode as set by the track effect command set speed (0x60) or zero if the set speed effect was not used yet during playback. */ uint8_t speed_type; /** Play type, if the song bit is set, the sub-song is currently playing normally from the beginning to the end. Disk writers can use this flag to determine if there is the current mixing output should be really written. */ uint8_t play_type; /** Current trace counter for debugging synth sound instructions. Rest of playback data will not continue being processed if trace count does not equal to zero. */ uint16_t trace_count; } AVSequencerPlayerGlobals; /** AVSequencerPlayerHostChannel->flags bitfield. */ enum AVSequencerPlayerHostChannelFlags { AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ = 0x00000001, ///< Use linear frequency table instead of Amiga AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS = 0x00000002, ///< Playing back track in backwards direction AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK = 0x00000004, ///< Pattern break encountered AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL = 0x00000008, ///< Sample offset is interpreted as relative to current position AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN = 0x00000010, ///< Track panning is in surround mode AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN = 0x00000020, ///< Channel panning is also affected AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN = 0x00000040, ///< Channel panning uses surround mode AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX = 0x00000080, ///< Execute command effect at tick invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA = 0x00000100, ///< Tone portamento effect invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE = 0x00000200, ///< Set transpose effect invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG = 0x00000400, ///< Allow sub-slides in multi retrigger note AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC = 0x00000800, ///< Tremor effect in hold, i.e. invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF = 0x00001000, ///< Tremor effect is currently turning off volume AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE = 0x00002000, ///< Note retrigger effect invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO = 0x00004000, ///< Vibrato effect in hold, i.e. invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO = 0x00008000, ///< Tremolo effect in hold, i.e. invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN = 0x00010000, ///< Change pattern effect invoked AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP = 0x00020000, ///< Performing pattern loop effect AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP = 0x00040000, ///< Pattern loop effect has jumped back AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET = 0x00080000, ///< Pattern loop effect needs to be resetted AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT = 0x00100000, ///< Only playing instrument without order list and pattern processing AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE = 0x00200000, ///< Only playing sample without instrument, order list and pattern processing + AVSEQ_PLAYER_HOST_CHANNEL_FLAG_NO_TRANSPOSE = 0x00400000, ///< Instrument can't be transpoed by the order list + AVSEQ_PLAYER_HOST_CHANNEL_FLAG_DEFAULT_PANNING = 0x00800000, ///< Use instrument panning and override sample default panning AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END = 0x80000000, ///< Song end triggered for this host channel / track }; /** AVSequencerPlayerHostChannel->fine_slide_flags bitfield. */ enum AVSequencerPlayerHostChannelFineSlideFlags { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN = 0x00000001, ///< Fine portamento is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN = 0x00000002, ///< Portamento once is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN = 0x00000004, ///< Fine portamento once is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA = 0x00000008, ///< Fine portamento invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE = 0x00000010, ///< Portamento once invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TONE_PORTA = 0x00000020, ///< Fine tone portamento invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TONE_PORTA_ONCE = 0x00000040, ///< Tone portamento once invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN = 0x00000080, ///< Volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN = 0x00000100, ///< Fine volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE = 0x00000200, ///< Fine volume slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN = 0x00000400, ///< Track volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN = 0x00000800, ///< Fine track volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE = 0x00001000, ///< Fine track volume slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT = 0x00002000, ///< Panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT = 0x00004000, ///< Fine panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE = 0x00008000, ///< Fine panning slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT = 0x00010000, ///< Track panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT = 0x00020000, ///< Fine track panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE = 0x00040000, ///< Fine track panning slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER = 0x00080000, ///< Speed slide is directed towards slowness AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER = 0x00100000, ///< Fine speed slide is directed towards slowness AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE = 0x00200000, ///< Fine speed slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN = 0x00400000, ///< Global volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN = 0x00800000, ///< Fine global volume slide is directed downwards AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE = 0x01000000, ///< Fine global volume slide invoked AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT = 0x02000000, ///< Global panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT = 0x04000000, ///< Fine global panning slide is directed towards right AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE = 0x08000000, ///< Fine global panning slide invoked }; /** AVSequencerPlayerHostChannel->env_ctrl_kind bitfield. */ enum AVSequencerPlayerHostChannelEnvCtrlKind { AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_VOLUME_ENV = 0x00, ///< Volume envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_PANNING_ENV = 0x01, ///< Panning envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_SLIDE_ENV = 0x02, ///< Slide envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_VIBRATO_ENV = 0x03, ///< Vibrato envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_TREMOLO_ENV = 0x04, ///< Tremolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_PANNOLO_ENV = 0x05, ///< Pannolo (panbrello) envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_CHANNOLO_ENV = 0x06, ///< Channolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_SPENOLO_ENV = 0x07, ///< Spenolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_AUTO_VIB_ENV = 0x08, ///< Auto vibrato envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_AUTO_TREM_ENV = 0x09, ///< Auto tremolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_AUTO_PAN_ENV = 0x0A, ///< Auto pannolo (panbrello) envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_TRACK_TREMO_ENV = 0x0B, ///< Track tremolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_TRACK_PANNO_ENV = 0x0C, ///< Track pannolo (panbrello) envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_GLOBAL_TREM_ENV = 0x0D, ///< Global tremolo envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_GLOBAL_PAN_ENV = 0x0E, ///< Global pannolo (panbrello) envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_ARPEGGIO_ENV = 0x0F, ///< Arpeggio definition envelope selected AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_KIND_SEL_RESONANCE_ENV = 0x10, ///< Resonance filter envelope selected }; /** AVSequencerPlayerHostChannel->env_ctrl_change bitfield. */ enum AVSequencerPlayerHostChannelEnvCtrlChange { AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_SET_WAVEFORM = 0x00, ///< Set the waveform number AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RESET_ENVELOPE = 0x10, ///< Reset envelope AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RETRIGGER_OFF = 0x01, ///< Turn off retrigger AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RETRIGGER_ON = 0x11, ///< Turn on retrigger AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_OFF = 0x02, ///< Turn off randomization AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_ON = 0x12, ///< Turn on randomization AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_DELAY_OFF = 0x22, ///< Turn off randomization delay AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_DELAY_ON = 0x32, ///< Turn on randomization delay AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_COUNT_AND_SET_OFF = 0x03, ///< Turn off count and set AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_COUNT_AND_SET_ON = 0x13, ///< Turn on count and set AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_POSITION_BY_TICK = 0x04, ///< Set envelope position by number of ticks AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_POSITION_BY_NODE = 0x14, ///< Set envelope position by node number AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_TEMPO = 0x05, ///< Set envelope tempo AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RELATIVE_TEMPO = 0x15, ///< Set relative envelope tempo AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_FINE_TEMPO = 0x25, ///< Set fine envelope tempo (count) AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_SUSTAIN_LOOP_START = 0x06, ///< Set sustain loop start point AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_SUSTAIN_LOOP_END = 0x07, ///< Set sustain loop end point AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_SUSTAIN_LOOP_COUNT = 0x08, ///< Set sustain loop count value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_SUSTAIN_LOOP_COUNTED = 0x09, ///< Set sustain loop counted value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_START = 0x0A, ///< Set normal loop start point AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_START_CURRENT = 0x1A, ///< Set normal current loop start value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_END = 0x0B, ///< Set normal loop end point AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_END_CURRENT = 0x1B, ///< Set normal current loop end point AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_COUNT = 0x0C, ///< Set normal loop count value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_LOOP_COUNTED = 0x0D, ///< Set normal loop counted value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_MIN = 0x0E, ///< Set randomization minimum value AVSEQ_PLAYER_HOST_CHANNEL_ENV_CTRL_RANDOM_MAX = 0x0F, ///< Set randomization maximum value }; /** AVSequencerPlayerHostChannel->synth_ctrl_change bitfield. */ enum AVSequencerPlayerHostChannelSynthCtrlChange { AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VOL_CODE_LINE = 0x00, ///< Set volume handling code position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PAN_CODE_LINE = 0x01, ///< Set panning handling code position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SLD_CODE_LINE = 0x02, ///< Set slide handling code position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SPC_CODE_LINE = 0x03, ///< Set special handling code position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VOL_SUSTAIN_CODE_LINE = 0x04, ///< Set volume sustain release position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PAN_SUSTAIN_CODE_LINE = 0x05, ///< Set panning sustain release position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SLD_SUSTAIN_CODE_LINE = 0x06, ///< Set slide sustain release position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SPC_SUSTAIN_CODE_LINE = 0x07, ///< Set special sustain release position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VOL_NNA_CODE_LINE = 0x08, ///< Set volume NNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PAN_NNA_CODE_LINE = 0x09, ///< Set panning NNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SLD_NNA_CODE_LINE = 0x0A, ///< Set slide NNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SPC_NNA_CODE_LINE = 0x0B, ///< Set special NNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VOL_DNA_CODE_LINE = 0x0C, ///< Set volume DNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PAN_DNA_CODE_LINE = 0x0D, ///< Set panning DNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SLD_DNA_CODE_LINE = 0x0E, ///< Set slide DNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SPC_DNA_CODE_LINE = 0x0F, ///< Set special DNA trigger position AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VARIABLE_MIN = 0x10, ///< Set first variable specified by the lowest 4 bits AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VARIABLE_MAX = 0x1F, ///< Set last variable specified by the lowest 4 bits AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VOL_CONDITION_VARIABLE = 0x20, ///< Set volume condition variable value AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PAN_CONDITION_VARIABLE = 0x21, ///< Set panning condition variable value AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SLD_CONDITION_VARIABLE = 0x22, ///< Set slide condition variable value AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SPC_CONDITION_VARIABLE = 0x23, ///< Set special condition variable value AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_SAMPLE_WAVEFORM = 0x24, ///< Set sample waveform AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_VIBRATO_WAVEFORM = 0x25, ///< Set vibrato waveform AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_TREMOLO_WAVEFORM = 0x26, ///< Set tremolo waveform AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_PANNOLO_WAVEFORM = 0x27, ///< Set pannolo (panbrello) waveform AVSEQ_PLAYER_HOST_CHANNEL_SYNTH_CTRL_SET_ARPEGGIO_WAVEFORM = 0x28, ///< Set arpeggio waveform }; /** AVSequencerPlayerHostChannel->dct values. */ enum AVSequencerPlayerHostChannelDCT { AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR = 0x01, ///< Check for duplicate OR instrument notes AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR = 0x02, ///< Check for duplicate OR sample notes AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR = 0x04, ///< Check for duplicate OR instruments AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR = 0x08, ///< Check for duplicate OR samples AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND = 0x10, ///< Check for duplicate AND instrument notes AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND = 0x20, ///< Check for duplicate AND sample notes AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND = 0x40, ///< Check for duplicate AND instruments AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND = 0x80, ///< Check for duplicate AND samples }; /** AVSequencerPlayerHostChannel->dna values. */ enum AVSequencerPlayerHostChannelDNA { AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT = 0x00, ///< Do note cut on duplicate note AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF = 0x01, ///< Perform keyoff on duplicate note AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE = 0x02, ///< Fade off notes on duplicate note AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CONTINUE = 0x03, ///< Nothing (only useful for synth sound handling) }; /** AVSequencerPlayerHostChannel->nna values. */ enum AVSequencerPlayerHostChannelNNA { AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT = 0x00, ///< Cut previous note AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CONTINUE = 0x01, ///< Continue previous note AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF = 0x02, ///< Perform key-off on previous note AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE = 0x03, ///< Perform fadeout on previous note }; /** AVSequencerPlayerHostChannel->ch_control_flags bitfield. */ enum AVSequencerPlayerHostChannelChControlFlags { AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_FLAG_NOTES = 0x01, ///< Affect note related effects (volume, panning, etc.) AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_FLAG_NON_NOTES = 0x02, ///< Affect non-note related effects (pattern loops and breaks, etc.) }; /** AVSequencerPlayerHostChannel->ch_control_type values. */ enum AVSequencerPlayerHostChannelChControlType { AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_OFF = 0x00, ///< Channel control is turned off AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL = 0x01, ///< Normal single channel control AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE = 0x02, ///< Multiple channels are controlled AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_GLOBAL = 0x03, ///< All channels are controlled }; /** AVSequencerPlayerHostChannel->ch_control_mode values. */ enum AVSequencerPlayerHostChannelChControlMode { AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_MODE_NORMAL = 0x00, ///< Channel control is for one effect AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_MODE_TICK = 0x01, ///< Channel control is for one tick AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_MODE_ROW = 0x02, ///< Channel control is for one row AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_MODE_TRACK = 0x03, ///< Channel control is for one row AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_MODE_SONG = 0x04, ///< Channel control is for the whole sub-song }; /** AVSequencerPlayerHostChannel->ch_control_affect bitfield. */ enum AVSequencerPlayerHostChannelChControlAffect { AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_AFFECT_NOTES = 0x01, ///< Affect note related effects (volume, panning, etc.) AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_AFFECT_NON_NOTES = 0x02, ///< Affect non-note related effects (pattern loops and breaks, etc.) }; /** AVSequencerPlayerHostChannel->cond_var bitfield. */ enum AVSequencerPlayerHostChannelCondVar { AVSEQ_PLAYER_HOST_CHANNEL_COND_VAR_CARRY = 0x01, ///< Carry (C) bit for condition variable AVSEQ_PLAYER_HOST_CHANNEL_COND_VAR_OVERFLOW = 0x02, ///< Overflow (V) bit for condition variable AVSEQ_PLAYER_HOST_CHANNEL_COND_VAR_ZERO = 0x04, ///< Zero (Z) bit for condition variable AVSEQ_PLAYER_HOST_CHANNEL_COND_VAR_NEGATIVE = 0x08, ///< Negative (N) bit for condition variable AVSEQ_PLAYER_HOST_CHANNEL_COND_VAR_EXTEND = 0x10, ///< Extend (X) bit for condition variable }; #include "libavsequencer/order.h" #include "libavsequencer/track.h" #include "libavsequencer/sample.h" #include "libavsequencer/synth.h" /** * Player host channel data structure used by playback engine for * processing the host channels which are the channels associated * to tracks and the note data is encountered upon. This contains * effect memories and all data required for track playback. This * structure is actually for one host channel and therefore actually * pointed as an array with size of number of host channels. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerHostChannel { /** Pointer to sequencer order data entry currently being played by this host channel. */ AVSequencerOrderData *order; /** Pointer to sequencer track data currently being played by this host channel. */ const AVSequencerTrack *track; /** Pointer to sequencer track effect currently being processed by this host channel. */ const AVSequencerTrackEffect *effect; /** Pointer to sequencer instrument currently being played by this host channel. */ const AVSequencerInstrument *instrument; /** Pointer to sequencer sample currently being played by this host channel. */ const AVSequencerSample *sample; /** Current row of track being played by this host channel. */ uint16_t row; /** Current fine pattern delay value or 0 if the fine pattern delay effect was not used yet during playback. */ uint16_t fine_pattern_delay; /** Current tempo counter (tick of row). The next row will be played when the tempo counter reaches the tempo value. */ uint32_t tempo_counter; /** Current last row of track being played before breaking to next track by this host channel. */ uint32_t max_row; /** Player host channel flags. This stores certain information about the current track and track effects being processed and also about the current playback mode. Trackers, for example can play a simple instrument or sample only or even play a single note on a single row if both set instrument and set sample bits are set (0x00300000). */ uint32_t flags; /** Player host channel fine slide flags. This stores information about the slide commands, i.e. which direction and invoke state to be handled for the playback engine, i.e. execution of the actual slides while remaining expected behaviour. */ uint32_t fine_slide_flags; /** Current tempo (number of ticks of row). The next row will be played when the tempo counter reaches this value. */ uint16_t tempo; /** Current final note being played (after applying all transpose values, etc.) by the formula: current octave * 12 + current note where C-0 is represented with a value zero. */ int16_t final_note; /** Current instrument note being played (after applying current instrument transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t instr_note; /** Current sample note being played (after applying current sample transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t sample_note; /** Current track volume being played on this host channel. */ uint8_t track_volume; /** Current track sub-volume level for this host channel. This is basically track volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t track_sub_volume; /** Current track panning stereo position being played on this host channel. */ int8_t track_panning; /** Current track sub-panning stereo position for this host channel. This is basically track panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t track_sub_panning; /** Current track note panning which indicates a panning change relative to a base note and octave. This allows choosing the stereo position based on octave * 12 + note. */ int8_t track_note_panning; /** Current track note sub-panning stereo position for this host channel. This is basically track note panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t track_note_sub_panning; /** Current chhannel panning stereo position being played on this host channel. */ int8_t channel_panning; /** Current channel sub-panning stereo position for this host channel. This is basically channel panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t channel_sub_panning; /** Current finetune of the sample last played on this host channel. */ int8_t finetune; /** Current arpeggio tick count. If tick count modulo 3 is 0, then use arpeggio base note. If modulo value is 1 instead, use first arpeggio value and second arpeggio value for a modulo value of 2. This value is 0 if the arpeggio effect was not used yet during playback. */ uint8_t arpeggio_tick; /** Current arpeggio frequency relative to played sample frequency to be able to undo the previous arpeggio frequency changes or 0 if the arpeggio effect was not used yet during playback. */ int32_t arpeggio_freq; /** Current arpeggio first value which will be used if modulo of arpeggio tick count modulo 3 is 1. This value is 0 if the arpeggio effect was not used yet during playback. */ int8_t arpeggio_first; /** Current arpeggio second value which will be used if modulo of arpeggio tick count modulo 3 is 2. This value is 0 if the arpeggio effect was not used yet during playback. */ int8_t arpeggio_second; /** Current high 16-bits for the sample offset high word command or 0 if the arpeggio effect was not used yet during playback. The final sample position will be set to this value * 0x10000 adding the data word of the sample offset low word command. */ uint16_t smp_offset_hi; /** Up to 4 channel numbers to be synchronized with. This is also used with the channel synchronization command. If multiple channels have identical values, they are synchronized only once. However, if all four channel numbers are 0, then the synchronization process is done with all channels. This is also the case if the channel synchronization effect was not used yet during playback. */ uint8_t channel_sync[4]; /** Current portamento up slide value or 0 if the portamento up effect was not used yet during playback. */ uint16_t porta_up; /** Current portamento down slide value or 0 if the portamento down effect was not used yet during playback. */ uint16_t porta_down; /** Current fine portamento up slide value or 0 if the fine portamento up effect was not used yet during playback. */ uint16_t fine_porta_up; /** Current fine portamento down slide value or 0 if the fine portamento down effect was not used yet during playback. */ uint16_t fine_porta_down; /** Current portamento up once slide value or 0 if the portamento up once effect was not used yet during playback. */ uint16_t porta_up_once; /** Current portamento down once slide value or 0 if the portamento down once effect was not used yet during playback. */ uint16_t porta_down_once; /** Current fine portamento up once slide value or 0 if the fine portamento up once effect was not used yet during playback. */ uint16_t fine_porta_up_once; /** Current fine portamento down once slide value or 0 if the fine portamento down once effect was not used yet during playback. */ uint16_t fine_porta_down_once; /** Current tone portamento slide value or 0 if the tone portamento effect was not used yet during playback. */ uint16_t tone_porta; /** Current fine tone portamento slide value or 0 if the fine tone portamento effect was not used yet during playback. */ uint16_t fine_tone_porta; /** Current tone portamento once slide value or 0 if the tone portamento once effect was not used yet during playback. */ uint16_t tone_porta_once; /** Current fine tone portamento once slide value or 0 if the fine tone portamento once effect was not used yet during playback. */ uint16_t fine_tone_porta_once; /** Current tone portamento target pitch or 0 if none of the tone portamento effects were used yet during playback. */ uint32_t tone_porta_target_pitch; /** Current sub-slide value for for all portamento effects or 0 if neither one of the portamento effects nor the extended control effect were used yet during playback. */ uint8_t sub_slide; /** Current note slide type or 0 if the note slide effect was not used yet during playback.. */ uint8_t note_slide_type; /** Current note slide value or 0 if the note slide effect was not used yet during playback.. */ uint8_t note_slide; /** Current glissando value or 0 if the glissando control effect was not used yet during playback.. */ uint8_t glissando; /** Current vibrato frequency relative to played sample frequency to be able to undo the previous vibrato frequency changes or 0 if the vibrato effect was not used yet during playback. */ int32_t vibrato_slide; /** Current vibrato rate value or 0 if the vibrato effect was not used yet during playback. */ uint16_t vibrato_rate; /** Current vibrato depth value or 0 if the vibrato effect was not used yet during playback. */ int16_t vibrato_depth; /** Current tick number of note delay command or 0 if the note delay effect was not used yet during playback. */ uint16_t note_delay; /** Current number of on ticks for tremor command. During this number of ticks, the tremor command will not playback the note at a muted level. This can be 0 if the tremor effect was not used yet during playback. */ uint8_t tremor_on_ticks; /** Current number of off ticks for tremor command. During this number of ticks, the tremor command will playback the note at a muted level. This can be 0 if the tremor effect was not used yet during playback. */ uint8_t tremor_off_ticks; /** Current number of tick for tremor command. This will allow the player to determine if we are currently in a tremor on or tremor off phase and can also be 0 if the tremor effect was not used yet during playback. */ uint8_t tremor_count; /** Current mask of sub-slide bits or 0 if the set target sub-slide to effect was not used yet during playback. */ uint8_t sub_slide_bits; /** Current retrigger tick counter or 0 if the note retrigger effect was not used yet during playback. */ uint16_t retrig_tick_count; /** Current multi retrigger note tick counter or 0 if the multi retrigger note effect was not used yet during playback. */ uint8_t multi_retrig_tick; /** Current multi retrigger note volume change or 0 if the multi retrigger note effect was not used yet during playback. */ uint8_t multi_retrig_vol_chg; /** Current multi retrigger note scale ranging from 1 to 4 or 0 if the multi retrigger note effect was not used yet during playback. */ uint8_t multi_retrig_scale; /** Current invert loop count or 0 if the invert loop effect was not used yet during playback. */ uint8_t invert_count; /** Current invert loop speed or 0 if the invert loop effect was not used yet during playback. */ uint16_t invert_speed; /** Current tick number where the next effect could be executed or 0 if the execute command effect at tick effect was not used yet during playback. */ uint16_t exec_fx; /** Current volume slide to speed or 0 if the volume slide to effect was not used yet during playback. */ uint8_t volume_slide_to; /** Current track volume slide to speed or 0 if the track volume slide to effect was not used yet during playback. */ uint8_t track_vol_slide_to; /** Current panning slide to speed or 0 if the panning slide to effect was not used yet during playback. */ uint8_t panning_slide_to; /** Current track panning slide to speed or 0 if the track panning slide to effect was not used yet during playback. */ uint8_t track_pan_slide_to; /** Current volume slide up value or 0 if the volume slide up effect was not used yet during playback. */ uint16_t vol_slide_up; /** Current volume slide down value or 0 if the volume slide down
BastyCDGS/ffmpeg-soc
7bbf075cb8557b9cf49bf3a266b94c7ba16bbd73
Implemented instrument change effect in AVSequencer player and added change instrument note swing to it, also fixed some nits.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 3aebfc2..e4219cf 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -3753,1025 +3753,1453 @@ EXECUTE_EFFECT(panning_slide_to) panning_slide_to_panning = data_word >> 8; if (panning_slide_to_panning && (panning_slide_to_panning < 0xFF)) { player_host_channel->panning_slide_to_panning = panning_slide_to_panning; } else if (panning_slide_to_panning && (player_channel->host_channel == channel)) { const uint16_t panning_slide_target = ((uint8_t) panning_slide_to_panning << 8) + player_host_channel->panning_slide_to_sub_panning; uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < panning_slide_target) { do_panning_slide_right(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target <= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } else { do_panning_slide(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target >= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } } } EXECUTE_EFFECT(pannolo) { int16_t pannolo_slide_value; uint8_t pannolo_rate; int16_t pannolo_depth; if (!(pannolo_rate = (data_word >> 8))) pannolo_rate = player_host_channel->pannolo_rate; player_host_channel->pannolo_rate = pannolo_rate; if (!(pannolo_depth = (int8_t) data_word)) pannolo_depth = player_host_channel->pannolo_depth; player_host_channel->pannolo_depth = pannolo_depth; pannolo_slide_value = (-(int32_t) pannolo_depth * run_envelope(avctx, &player_host_channel->pannolo_env, pannolo_rate, 0)) >> 7; if (player_channel->host_channel == channel) { const int16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_host_channel->pannolo_slide; if ((int16_t) (pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_host_channel->pannolo_slide -= panning - pannolo_slide_value; player_host_channel->track_note_panning = player_host_channel->track_panning = panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_channel->sub_panning; } } EXECUTE_EFFECT(set_track_panning) { player_host_channel->channel_panning = data_word >> 8; player_host_channel->channel_sub_panning = data_word; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; } EXECUTE_EFFECT(track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->track_pan_slide_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->fine_trk_pan_sld_right; v8 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_pan_slide_left = data_word; player_host_channel->track_pan_slide_right = v3; player_host_channel->fine_trk_pan_sld_left = v4; player_host_channel->fine_trk_pan_sld_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->track_pan_slide_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v3 = player_host_channel->fine_trk_pan_sld_left; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = data_word; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = data_word; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v3 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(track_panning_slide_to) { uint8_t track_pan_slide_to, track_panning_slide_to_panning; if (!(track_pan_slide_to = (uint8_t) data_word)) track_pan_slide_to = player_host_channel->track_pan_slide_to; player_host_channel->track_pan_slide_to = track_pan_slide_to; player_host_channel->track_pan_slide_to_slide &= 0x00FF; player_host_channel->track_pan_slide_to_slide += track_pan_slide_to << 8; track_panning_slide_to_panning = data_word >> 8; if (track_panning_slide_to_panning && (track_panning_slide_to_panning < 0xFF)) { player_host_channel->track_pan_slide_to_panning = track_panning_slide_to_panning; } else if (track_panning_slide_to_panning) { const uint16_t track_panning_slide_to_target = ((uint8_t) track_panning_slide_to_panning << 8) + player_host_channel->track_pan_slide_to_sub_panning; uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning < track_panning_slide_to_target) { do_track_panning_slide_right(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target <= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } else { do_track_panning_slide(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target >= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } } } EXECUTE_EFFECT(track_pannolo) { int16_t track_pannolo_slide_value; uint8_t track_pannolo_rate; int16_t track_pannolo_depth; uint16_t track_panning; if (!(track_pannolo_rate = (data_word >> 8))) track_pannolo_rate = player_host_channel->track_pan_rate; player_host_channel->track_pan_rate = track_pannolo_rate; if (!(track_pannolo_depth = (int8_t) data_word)) track_pannolo_depth = player_host_channel->track_pan_depth; player_host_channel->track_pan_depth = track_pannolo_depth; track_pannolo_slide_value = (-(int32_t) track_pannolo_depth * run_envelope(avctx, &player_host_channel->track_pan_env, track_pannolo_rate, 0)) >> 7; track_panning = (uint8_t) player_host_channel->track_panning; track_pannolo_slide_value -= player_host_channel->track_pan_slide; if ((int16_t) (track_pannolo_slide_value += track_panning) < 0) track_pannolo_slide_value = 0; if (track_pannolo_slide_value > 255) track_pannolo_slide_value = 255; player_host_channel->track_panning = track_pannolo_slide_value; player_host_channel->track_pan_slide -= track_panning - track_pannolo_slide_value; } EXECUTE_EFFECT(set_tempo) { if (!(player_host_channel->tempo = data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(set_relative_tempo) { if (!(player_host_channel->tempo += data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(pattern_break) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = data_word; } } EXECUTE_EFFECT(position_jump) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { AVSequencerOrderData *order_data = NULL; if (data_word--) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; if ((data_word < order_list->orders) && order_list->order_data[data_word]) order_data = order_list->order_data[data_word]; } player_host_channel->order = order_data; pattern_break(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_PATT_BREAK, 0); } } EXECUTE_EFFECT(relative_position_jump) { if (!data_word) data_word = player_host_channel->pos_jump; if ((player_host_channel->pos_jump = data_word)) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; AVSequencerOrderData *order_data = player_host_channel->order; uint32_t ord = -1; while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; ord++; } ord += (int32_t) data_word; if (ord > 0xFFFF) ord = 0; position_jump(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_POS_JUMP, (uint16_t) ord); } } EXECUTE_EFFECT(change_pattern) { player_host_channel->chg_pattern = data_word; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; } EXECUTE_EFFECT(reverse_pattern_play) { if (!data_word) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else if (data_word & 0x8000) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; } EXECUTE_EFFECT(pattern_delay) { player_host_channel->pattern_delay = data_word; } EXECUTE_EFFECT(fine_pattern_delay) { player_host_channel->fine_pattern_delay = data_word; } EXECUTE_EFFECT(pattern_loop) { const AVSequencerSong *const song = avctx->player_song; uint16_t *loop_stack_ptr; uint16_t loop_length = player_host_channel->pattern_loop_depth; loop_stack_ptr = (uint16_t *) avctx->player_globals->loop_stack + (((song->loop_stack_size * channel) * sizeof (uint16_t[2])) + (loop_length * sizeof(uint16_t[2]))); if (data_word) { if (data_word == *loop_stack_ptr) { *loop_stack_ptr = 0; if (loop_length--) player_host_channel->pattern_loop_depth = loop_length; else player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; } else { (*loop_stack_ptr++)++; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; player_host_channel->break_row = *loop_stack_ptr; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } } else if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; *loop_stack_ptr++ = 0; *loop_stack_ptr = player_host_channel->row; if (++loop_length != song->loop_stack_size) player_host_channel->pattern_loop_depth = loop_length; } } EXECUTE_EFFECT(gosub) { // TODO: Implement GoSub effect } EXECUTE_EFFECT(gosub_return) { // TODO: Implement return effect } EXECUTE_EFFECT(channel_sync) { // TODO: Implement channel synchronizattion effect } EXECUTE_EFFECT(set_sub_slides) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t sub_slide_flags; if (!(sub_slide_flags = (data_word >> 8))) sub_slide_flags = player_host_channel->sub_slide_bits; if (sub_slide_flags & 0x01) player_host_channel->volume_slide_to_volume = data_word; if (sub_slide_flags & 0x02) player_host_channel->track_vol_slide_to_sub_volume = data_word; if (sub_slide_flags & 0x04) player_globals->global_volume_sl_to_sub_volume = data_word; if (sub_slide_flags & 0x08) player_host_channel->panning_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x10) player_host_channel->track_pan_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x20) player_globals->global_pan_slide_to_sub_panning = data_word; } EXECUTE_EFFECT(sample_offset_high) { player_host_channel->smp_offset_hi = data_word; } EXECUTE_EFFECT(sample_offset_low) { if (player_channel->host_channel == channel) { uint32_t sample_offset = (player_host_channel->smp_offset_hi << 16) + data_word; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL)) { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SAMPLE_OFFSET) { const AVSequencerSample *const sample = player_channel->sample; if (sample_offset >= sample->samples) return; } player_channel->mixer.pos = 0; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t repeat_end = player_channel->mixer.repeat_start + player_channel->mixer.repeat_length; if (repeat_end < sample_offset) sample_offset = repeat_end; } } player_channel->mixer.pos += sample_offset; } } EXECUTE_EFFECT(set_hold) { // TODO: Implement set hold effect } EXECUTE_EFFECT(set_decay) { // TODO: Implement set decay effect } EXECUTE_EFFECT(set_transpose) { // TODO: Implement set transpose effect } EXECUTE_EFFECT(instrument_ctrl) { // TODO: Implement instrument control effect } EXECUTE_EFFECT(instrument_change) { - // TODO: Implement instrument change effect + const AVSequencerInstrument *instrument; + const AVSequencerSample *sample; + AVMixerData *mixer; + uint32_t volume, volume_swing, panning, abs_volume_swing, seed; + + switch (data_word >> 12) { + case 0x0 : + sample = player_host_channel->sample; + volume = player_channel->instr_volume; + player_channel->global_instr_volume = data_word; + + if (sample && (instrument = player_host_channel->instrument)) { + volume = sample->global_volume * player_channel->global_instr_volume; + volume_swing = (volume * player_channel->volume_swing) >> 8; + abs_volume_swing = (volume_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; + abs_volume_swing -= volume_swing; + + if ((int32_t) (volume += abs_volume_swing) < 0) + volume = 0; + + if (volume > (255*255)) + volume = 255*255; + } else if (sample) { + volume = player_channel->global_instr_volume * 255; + } + + player_channel->instr_volume = volume; + + break; + case 0x1 : + sample = player_host_channel->sample; + volume = player_channel->instr_volume; + volume_swing = data_word & 0xFFF; + + if (sample && (instrument = player_host_channel->instrument)) { + volume = sample->global_volume * player_channel->global_instr_volume; + volume_swing = (volume * volume_swing) >> 8; + abs_volume_swing = (volume_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; + abs_volume_swing -= volume_swing; + + if ((int32_t) (volume += abs_volume_swing) < 0) + volume = 0; + + if (volume > (255*255)) + volume = 255*255; + } else if (sample) { + volume = sample->global_volume * 255; + volume_swing = (volume * instrument->volume_swing) >> 8; + abs_volume_swing = (volume_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; + abs_volume_swing -= volume_swing; + + if ((int32_t) (volume += abs_volume_swing) < 0) + volume = 0; + + if (volume > (255*255)) + volume = 255*255; + } + + player_channel->instr_volume = volume; + player_channel->volume_swing = volume_swing; + + break; + case 0x2 : + if ((sample = player_host_channel->sample)) { + panning = (uint8_t) player_host_channel->track_note_panning; + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = sample->panning; + player_channel->sub_panning = sample->sub_panning; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->track_note_panning = panning; + player_host_channel->track_note_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } else { + player_channel->panning = player_host_channel->track_panning; + player_channel->sub_panning = player_host_channel->track_sub_panning; + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + } + + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if ((instrument = player_channel->instrument)) { + uint32_t panning_swing; + int32_t panning_separation; + + player_channel->panning_swing = panning_swing = data_word & 0xFFF; + + if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = instrument->default_panning; + player_channel->sub_panning = instrument->default_sub_pan; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = player_channel->panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } + + panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; + panning_swing = (panning_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + panning_swing = ((uint64_t) seed * panning_swing) >> 32; + panning_swing -= instrument->panning_swing; + panning += panning_swing; + + if ((int32_t) (panning += panning_separation) < 0) + panning = 0; + + if (panning > 255) + panning = 255; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) + player_host_channel->track_panning = panning; + else + player_channel->panning = panning; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { + player_host_channel->track_panning = panning; + player_channel->panning = panning; + } + } + } + + break; + case 0x3 : + player_channel->pitch_swing = (((uint32_t) data_word & 0xFFF) << 16) / 100; + + break; + case 0x4 : + player_channel->fade_out = data_word << 4; + + break; + case 0x5 : + if (data_word & 0xFFF) + player_channel->fade_out_count = data_word << 4; + else + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_FADING; + + break; + case 0x6 : + switch ((data_word >> 8) & 0xF) { + case 0x0 : + player_channel->auto_vibrato_sweep = data_word & 0xFF; + + break; + case 0x1 : + player_channel->auto_vibrato_depth = data_word; + + break; + case 0x2 : + player_channel->auto_vibrato_rate = data_word; + + break; + case 0x4 : + player_channel->auto_tremolo_sweep = data_word & 0xFF; + + break; + case 0x5 : + player_channel->auto_tremolo_depth = data_word; + + break; + case 0x6 : + player_channel->auto_tremolo_rate = data_word; + + break; + case 0x8 : + player_channel->auto_pannolo_sweep = data_word & 0xFF; + + break; + case 0x9 : + player_channel->auto_pannolo_sweep = data_word; + + break; + case 0xA : + player_channel->auto_pannolo_sweep = data_word; + + break; + } + + break; + case 0x7 : + if ((sample = player_host_channel->sample)) { + panning = (uint8_t) player_host_channel->track_note_panning; + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = sample->panning; + player_channel->sub_panning = sample->sub_panning; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->track_note_panning = panning; + player_host_channel->track_note_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } else { + player_channel->panning = player_host_channel->track_panning; + player_channel->sub_panning = player_host_channel->track_sub_panning; + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + } + + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if ((instrument = player_channel->instrument)) { + uint32_t panning_swing; + int32_t panning_separation; + + player_channel->pitch_pan_separation = data_word & 0xFFF; + + if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = instrument->default_panning; + player_channel->sub_panning = instrument->default_sub_pan; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = player_channel->panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } + + panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; + panning_swing = (player_channel->panning_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + panning_swing = ((uint64_t) seed * panning_swing) >> 32; + panning_swing -= instrument->panning_swing; + panning += panning_swing; + + if ((int32_t) (panning += panning_separation) < 0) + panning = 0; + + if (panning > 255) + panning = 255; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) + player_host_channel->track_panning = panning; + else + player_channel->panning = panning; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { + player_host_channel->track_panning = panning; + player_channel->panning = panning; + } + } + } + + break; + case 0x8 : + if ((sample = player_host_channel->sample)) { + panning = (uint8_t) player_host_channel->track_note_panning; + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = sample->panning; + player_channel->sub_panning = sample->sub_panning; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->track_note_panning = panning; + player_host_channel->track_note_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } else { + player_channel->panning = player_host_channel->track_panning; + player_channel->sub_panning = player_host_channel->track_sub_panning; + player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + } + + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if ((instrument = player_channel->instrument)) { + uint32_t panning_swing; + int32_t panning_separation; + + player_channel->pitch_pan_center = data_word; + + if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) + player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { + player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); + + if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) + player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; + + player_channel->panning = instrument->default_panning; + player_channel->sub_panning = instrument->default_sub_pan; + player_host_channel->pannolo_slide = 0; + panning = (uint8_t) player_channel->panning; + + if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { + player_host_channel->track_panning = player_channel->panning; + player_host_channel->track_sub_panning = player_channel->sub_panning; + player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) + player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; + } + } + + panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; + panning_swing = (player_channel->panning_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + panning_swing = ((uint64_t) seed * panning_swing) >> 32; + panning_swing -= instrument->panning_swing; + panning += panning_swing; + + if ((int32_t) (panning += panning_separation) < 0) + panning = 0; + + if (panning > 255) + panning = 255; + + if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) + player_host_channel->track_panning = panning; + else + player_channel->panning = panning; + + if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { + player_host_channel->track_panning = panning; + player_channel->panning = panning; + } + } + } + + break; + case 0x9 : + if ((data_word & 0xFFF) <= 2) + player_channel->dca = data_word; + + break; + case 0xA : + mixer = avctx->player_mixer_data; + player_channel->mixer.filter_cutoff = data_word & 0xFFF; + + if (mixer->mixctx->set_channel_filter) + mixer->mixctx->set_channel_filter(mixer, &player_channel->mixer, player_host_channel->virtual_channel); + + break; + case 0xB : + mixer = avctx->player_mixer_data; + player_channel->mixer.filter_damping = data_word & 0xFFF; + + if (mixer->mixctx->set_channel_filter) + mixer->mixctx->set_channel_filter(mixer, &player_channel->mixer, player_host_channel->virtual_channel); + + break; + case 0xC : + player_channel->note_swing = data_word; + + break; + } } EXECUTE_EFFECT(set_synth_value) { uint8_t synth_ctrl_count = player_host_channel->synth_ctrl_count; const uint16_t synth_ctrl_change = player_host_channel->synth_ctrl_change & 0x7F; player_host_channel->synth_ctrl = data_word; do { switch (synth_ctrl_change) { case 0x00 : case 0x01 : case 0x02 : case 0x03 : player_channel->entry_pos[synth_ctrl_change & 3] = data_word; break; case 0x04 : case 0x05 : case 0x06 : case 0x07 : player_channel->sustain_pos[synth_ctrl_change & 3] = data_word; break; case 0x08 : case 0x09 : case 0x0A : case 0x0B : player_channel->nna_pos[synth_ctrl_change & 3] = data_word; break; case 0x0C : case 0x0D : case 0x0E : case 0x0F : player_channel->dna_pos[synth_ctrl_change & 3] = data_word; break; case 0x10 : case 0x11 : case 0x12 : case 0x13 : case 0x14 : case 0x15 : case 0x16 : case 0x17 : case 0x18 : case 0x19 : case 0x1A : case 0x1B : case 0x1C : case 0x1D : case 0x1E : case 0x1F : player_channel->variable[synth_ctrl_change & 0xF] = data_word; break; case 0x20 : case 0x21 : case 0x22 : case 0x23 : player_channel->cond_var[synth_ctrl_change & 3] = data_word; break; case 0x24 : if (data_word < player_channel->synth->waveforms) player_channel->sample_waveform = player_channel->waveform_list[data_word]; break; case 0x25 : if (data_word < player_channel->synth->waveforms) player_channel->vibrato_waveform = player_channel->waveform_list[data_word]; break; case 0x26 : if (data_word < player_channel->synth->waveforms) player_channel->tremolo_waveform = player_channel->waveform_list[data_word]; break; case 0x27 : if (data_word < player_channel->synth->waveforms) player_channel->pannolo_waveform = player_channel->waveform_list[data_word]; break; case 0x28 : if (data_word < player_channel->synth->waveforms) player_channel->arpeggio_waveform = player_channel->waveform_list[data_word]; break; } } while (synth_ctrl_count--); } EXECUTE_EFFECT(synth_ctrl) { player_host_channel->synth_ctrl_count = data_word >> 8; player_host_channel->synth_ctrl_change = data_word; if (data_word & 0x80) set_synth_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_SYN_VAL, player_host_channel->synth_ctrl); } static const void *envelope_ctrl_type_lut[] = { use_volume_envelope, use_panning_envelope, use_slide_envelope, use_vibrato_envelope, use_tremolo_envelope, use_pannolo_envelope, use_channolo_envelope, use_spenolo_envelope, use_auto_vibrato_envelope, use_auto_tremolo_envelope, use_auto_pannolo_envelope, use_track_tremolo_envelope, use_track_pannolo_envelope, use_global_tremolo_envelope, use_global_pannolo_envelope, use_arpeggio_envelope, use_resonance_envelope }; EXECUTE_EFFECT(set_envelope_value) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); player_host_channel->env_ctrl = data_word; envelope_get_kind = envelope_ctrl_type_lut[player_host_channel->env_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (player_host_channel->env_ctrl_change) { case 0x00 : if ((data_word < module->envelopes) && ((instrument_envelope = module->envelope_list[data_word]))) envelope->envelope = instrument_envelope; else envelope->envelope = NULL; break; case 0x04 : envelope->pos = data_word; break; case 0x14 : if ((instrument_envelope = envelope->envelope)) { if (++data_word > instrument_envelope->nodes) data_word = instrument_envelope->nodes; envelope->pos = instrument_envelope->node_points[data_word - 1]; } break; case 0x05 : envelope->tempo = data_word; break; case 0x15 : envelope->tempo += data_word; break; case 0x25 : envelope->tempo_count = data_word; break; case 0x06 : envelope->sustain_start = data_word; break; case 0x07 : envelope->sustain_end = data_word; break; case 0x08 : envelope->sustain_count = data_word; break; case 0x09 : envelope->sustain_counted = data_word; break; case 0x0A : envelope->loop_start = data_word; break; case 0x1A : envelope->start = data_word; break; case 0x0B : envelope->loop_end = data_word; break; case 0x1B : envelope->end = data_word; break; case 0x0C : envelope->loop_count = data_word; break; case 0x0D : envelope->loop_counted = data_word; break; case 0x0E : envelope->value_min = data_word; break; case 0x0F : envelope->value_max = data_word; break; } } EXECUTE_EFFECT(envelope_ctrl) { const uint8_t envelope_ctrl_kind = (data_word >> 8) & 0x7F; if (envelope_ctrl_kind <= 0x10) { const uint8_t envelope_ctrl_type = data_word; player_host_channel->env_ctrl_kind = envelope_ctrl_kind; if (envelope_ctrl_type <= 0x32) { const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); envelope_get_kind = envelope_ctrl_type_lut[envelope_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (envelope_ctrl_type) { case 0x10 : if ((instrument_envelope = envelope->envelope)) { envelope->tempo = instrument_envelope->tempo; envelope->sustain_counted = 0; envelope->loop_counted = 0; envelope->tempo_count = 0; envelope->sustain_start = instrument_envelope->sustain_start; envelope->sustain_end = instrument_envelope->sustain_end; envelope->sustain_count = instrument_envelope->sustain_count; envelope->loop_start = instrument_envelope->loop_start; envelope->loop_end = instrument_envelope->loop_end; envelope->loop_count = instrument_envelope->loop_count; envelope->value_min = instrument_envelope->value_min; envelope->value_max = instrument_envelope->value_max; envelope->rep_flags = instrument_envelope->flags; set_envelope(player_channel, envelope, envelope->pos); } break; case 0x01 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; break; case 0x11 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; break; case 0x02 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x12 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x22 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x32 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x03 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; case 0x13 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; default : player_host_channel->env_ctrl_change = envelope_ctrl_type; if (data_word & 0x8000) set_envelope_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_ENV_VAL, player_host_channel->env_ctrl); break; } } } } EXECUTE_EFFECT(nna_ctrl) { const uint8_t nna_ctrl_type = data_word >> 8; uint8_t nna_ctrl_action = data_word; switch (nna_ctrl_type) { case 0x00 : switch (nna_ctrl_action) { case 0x00 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; break; case 0x01 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF; break; case 0x02 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CONTINUE; break; case 0x03 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE; break; } break; case 0x11 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct |= nna_ctrl_action; break; case 0x01 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct &= ~nna_ctrl_action; break; case 0x02 : player_host_channel->dna = nna_ctrl_action; break; } } EXECUTE_EFFECT(loop_ctrl) { // TODO: Implement loop control effect } EXECUTE_EFFECT(set_speed) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_value, speed_min_value, speed_max_value; uint8_t speed_type = data_word >> 12; if ((speed_ptr = get_speed_address(avctx, speed_type, &speed_min_value, &speed_max_value))) { if (!(speed_value = (data_word & 0xFFF))) { if ((data_word & 0x7000) == 0x7000) speed_value = (player_globals->speed_mul << 8U) + player_globals->speed_div; else speed_value = *speed_ptr; } speed_val_ok(avctx, speed_ptr, speed_value, speed_type, speed_min_value, speed_max_value); } } EXECUTE_EFFECT(speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_globals->speed_slide_faster; do_speed_slide(avctx, data_word); track = player_host_channel->track; v3 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_fast; v5 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->speed_slide_faster = data_word; player_globals->speed_slide_slower = v3; player_globals->fine_speed_slide_fast = v4; player_globals->fine_speed_slide_slow = v5; } EXECUTE_EFFECT(speed_slide_slower) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_globals->speed_slide_slower; do_speed_slide_slower(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v3 = player_globals->fine_speed_slide_fast; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = data_word; player_globals->fine_speed_slide_fast = v3; player_globals->fine_speed_slide_slow = v4; } EXECUTE_EFFECT(fine_speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_globals->fine_speed_slide_fast; do_speed_slide(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v1 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = v1; player_globals->fine_speed_slide_fast = data_word; player_globals->fine_speed_slide_slow = v4; } EXECUTE_EFFECT(fine_speed_slide_slower) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_globals->fine_speed_slide_slow; do_speed_slide_slower(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v1 = player_globals->speed_slide_slower; v3 = player_globals->fine_speed_slide_fast; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = v1; player_globals->fine_speed_slide_fast = v3; player_globals->fine_speed_slide_slow = data_word; } EXECUTE_EFFECT(speed_slide_to) { // TODO: Implement speed slide to effect } EXECUTE_EFFECT(spenolo) { // TODO: Implement spenolo effect } EXECUTE_EFFECT(channel_ctrl) { const uint8_t channel_ctrl_byte = data_word; switch (data_word >> 8) { case 0x00 : @@ -8232,1822 +8660,1830 @@ static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayer } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; if (!(keyboard = instrument->keyboard_defs)) goto do_not_play_keyboard; i = --note; note = ((uint16_t) (keyboard->key[i].octave & 0x7F) * 12) + keyboard->key[i].note; player_host_channel->sample_note = note; if ((smp = keyboard->key[i].sample)) { do_not_play_keyboard: smp--; if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES)) { if ((smp >= instrument->samples) || !(sample = instrument->sample_list[smp])) return 0x8000; } else { AVSequencerInstrument *scan_instrument; if ((smp >= module->instruments) || !(scan_instrument = module->instrument_list[smp])) return 0x8000; if (!scan_instrument->samples || !(sample = scan_instrument->sample_list[0])) return 0x8000; } } else { sample = player_host_channel->sample; if (!((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE) && sample)) return 0x8000; } player_host_channel->sample = sample; transpose = sample->transpose; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) transpose = player_host_channel->transpose; note += transpose; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE)) note += player_host_channel->order->transpose; note += player_host_channel->track->transpose; return note - 1; } static int16_t get_key_table_note(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, const uint16_t octave, const uint16_t note) { return get_key_table(avctx, instrument, player_host_channel, (octave * 12) + note); } static int trigger_dct(const AVSequencerPlayerHostChannel *const player_host_channel, const AVSequencerPlayerChannel *const player_channel, const unsigned dct) { int trigger = 0; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_OR) trigger |= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_OR) trigger |= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_OR) trigger |= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_OR) trigger |= player_host_channel->sample == player_channel->sample; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_NOTE_AND) trigger &= player_host_channel->instr_note == player_channel->instr_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_NOTE_AND) trigger &= player_host_channel->sample_note == player_channel->sample_note; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_INSTR_AND) trigger &= player_host_channel->instrument == player_channel->instrument; if (dct & AVSEQ_PLAYER_HOST_CHANNEL_DCT_SAMPLE_AND) trigger &= player_host_channel->sample == player_channel->sample; return trigger; } static AVSequencerPlayerChannel *trigger_nna(const AVSequencerContext *const avctx, const AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const virtual_channel) { const AVSequencerModule *const module = avctx->player_module; AVSequencerPlayerChannel *new_player_channel = player_channel; AVSequencerPlayerChannel *scan_player_channel; uint16_t nna_channel, nna_max_volume, nna_volume; uint8_t nna; *virtual_channel = player_host_channel->virtual_channel; if (player_channel->host_channel != channel) { new_player_channel = avctx->player_channel; nna_channel = 0; do { if (new_player_channel->host_channel == channel) goto previous_nna_found; new_player_channel++; } while (++nna_channel < module->channels); goto find_nna; previous_nna_found: *virtual_channel = nna_channel; } nna_volume = new_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; new_player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; if (nna_volume || !(nna = player_host_channel->nna)) goto nna_found; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA) new_player_channel->entry_pos[0] = new_player_channel->nna_pos[0]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA) new_player_channel->entry_pos[1] = new_player_channel->nna_pos[1]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA) new_player_channel->entry_pos[2] = new_player_channel->nna_pos[2]; if (new_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA) new_player_channel->entry_pos[3] = new_player_channel->nna_pos[3]; new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND; switch (nna) { case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF : play_key_off(new_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE : new_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; } if (!player_host_channel->dct || player_host_channel->dna) goto find_nna; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; - note_swing = (instrument->note_swing << 1) + 1; + note_swing = (player_channel->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; - note_swing -= instrument->note_swing; + note_swing -= player_channel->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } - note_swing = pitch_swing = ((uint64_t) frequency * instrument->pitch_swing) >> 16; + note_swing = pitch_swing = ((uint64_t) frequency * player_channel->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope * (**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope * (**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; - volume = sample->global_volume * instrument->global_volume; - volume_swing = (volume * instrument->volume_swing) >> 8; - abs_volume_swing = (volume_swing << 1) + 1; - avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; - abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; - abs_volume_swing -= volume_swing; + player_channel->global_instr_volume = instrument->global_volume; + player_channel->volume_swing = instrument->volume_swing; + volume = sample->global_volume * player_channel->global_volume; + volume_swing = (volume * player_channel->volume_swing) >> 8; + abs_volume_swing = (volume_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; + abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; - player_channel->auto_pan_sweep = sample->pannolo_sweep; + player_channel->auto_pannolo_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; - player_channel->auto_pan_depth = sample->pannolo_depth; - player_channel->auto_pan_rate = sample->pannolo_rate; + player_channel->auto_pannolo_depth = sample->pannolo_depth; + player_channel->auto_pannolo_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } - panning_separation = ((int32_t) instrument->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (instrument->pitch_pan_center + 1))) >> 8; - panning_swing = (instrument->panning_swing << 1) + 1; - avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; - panning_swing = ((uint64_t) seed * panning_swing) >> 32; - panning_swing -= instrument->panning_swing; - panning += panning_swing; + player_channel->pitch_pan_separation = instrument->pitch_pan_separation; + player_channel->pitch_pan_center = instrument->pitch_pan_center; + player_channel->panning_swing = instrument->panning_swing; + panning_separation = ((int32_t) player_channel->pitch_pan_separation * (int32_t) (player_host_channel->instr_note - (player_channel->pitch_pan_center + 1))) >> 8; + panning_swing = (player_channel->panning_swing << 1) + 1; + avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; + panning_swing = ((uint64_t) seed * panning_swing) >> 32; + panning_swing -= instrument->panning_swing; + panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } + + player_channel->note_swing = instrument->note_swing; + player_channel->pitch_swing = instrument->pitch_swing; } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || !(track = player_host_channel->track)) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || !(instrument = module->instrument_list[instr])) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; - new_player_channel->auto_pan_sweep = player_channel->auto_pan_sweep; + new_player_channel->auto_pannolo_sweep = player_channel->auto_pannolo_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; - new_player_channel->auto_pan_depth = player_channel->auto_pan_depth; - new_player_channel->auto_pan_rate = player_channel->auto_pan_rate; + new_player_channel->auto_pannolo_depth = player_channel->auto_pannolo_depth; + new_player_channel->auto_pannolo_rate = player_channel->auto_pannolo_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; if (player_channel->wait_count[synth_type]--) { exec_synth_done: if ((player_channel->synth_flags & bit_mask) && !(player_channel->kill_count[synth_type]--)) return 0; return 1; } player_channel->wait_count[synth_type] = 0; if ((synth_code_line >= synth->size) || ((int8_t) player_channel->wait_type[synth_type] < 0)) goto exec_synth_done; i = 4 - 1; do { int8_t wait_volume_type; if (((wait_volume_type = ~player_channel->wait_type[synth_type]) >= 0) && (wait_volume_type == i) && (player_channel->wait_line[synth_type] == synth_code_line)) player_channel->wait_type[synth_type] = 0; } while (i--); instruction = synth_code->instruction; dst_var = synth_code->src_dst_var; instruction_data = synth_code->data; if (!instruction && !dst_var && !instruction_data) goto exec_synth_done; src_var = dst_var >> 4; dst_var &= 0x0F; synth_code_line++; if (instruction < 0) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; fx_byte = ~instruction; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = instruction_data + player_channel->variable[src_var]; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, player_channel->host_channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!effects_lut->pre_pattern_func) { instruction_data = player_host_channel->virtual_channel; player_host_channel->virtual_channel = channel; effects_lut->effect_func(avctx, player_host_channel, player_channel, player_channel->host_channel, fx_byte, data_word); player_host_channel->virtual_channel = instruction_data; } player_channel->entry_pos[synth_type] = synth_code_line; } else { uint16_t (**fx_exec_func)(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint16_t virtual_channel, uint16_t synth_code_line, const int src_var, int dst_var, uint16_t instruction_data, const int synth_type); fx_exec_func = (avctx->synth_code_exec_lut ? avctx->synth_code_exec_lut : se_lut); player_channel->entry_pos[synth_type] = fx_exec_func[(uint8_t) instruction](avctx, player_channel, channel, synth_code_line, src_var, dst_var, instruction_data, synth_type); } } while (++synth_count); return 0; } static const int8_t empty_waveform[256]; int avseq_playback_handler(AVMixerData *mixer_data) { AVSequencerContext *const avctx = (AVSequencerContext *) mixer_data->opaque; const AVSequencerModule *const module = avctx->player_module; const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; AVSequencerPlayerHostChannel *player_host_channel = avctx->player_host_channel; AVSequencerPlayerChannel *player_channel = avctx->player_channel; const AVSequencerPlayerHook *player_hook; uint16_t channel, virtual_channel; if (!(module && song && player_globals && player_host_channel && player_channel)) return 0; channel = 0; do { if (mixer_data->mixctx->get_channel) mixer_data->mixctx->get_channel(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE) { if (!player_globals->trace_count--) player_globals->trace_count = 0; return 0; } player_hook = avctx->player_hook; if (player_hook && (player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || !(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->play_type & AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG) { uint32_t play_time_calc, play_time_advance, play_time_fraction; play_time_calc = ((uint64_t) player_globals->tempo * player_globals->relative_speed) >> 16; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_time_frac += play_time_fraction; if (player_globals->play_time_frac < play_time_fraction) play_time_advance++; player_globals->play_time += play_time_advance; play_time_calc = player_globals->tempo; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_tics_frac += play_time_fraction; if (player_globals->play_tics_frac < play_time_fraction) play_time_advance++; player_globals->play_tics += play_time_advance; } channel = 0; do { player_channel = avctx->player_channel + player_host_channel->virtual_channel; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE)) { const AVSequencerTrack *const old_track = player_host_channel->track; const AVSequencerTrackEffect const *old_effect = player_host_channel->effect; const uint32_t old_tempo_counter = player_host_channel->tempo_counter; const uint16_t old_row = player_host_channel->row; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE); player_host_channel->track = (const AVSequencerTrack *) player_host_channel->instrument; player_host_channel->effect = NULL; player_host_channel->row = (uint32_t) player_host_channel->sample; player_host_channel->instrument = NULL; player_host_channel->sample = NULL; get_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->tempo_counter = player_host_channel->note_delay; get_note(avctx, player_host_channel, player_channel, channel); run_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->track = old_track; player_host_channel->effect = old_effect; player_host_channel->tempo_counter = old_tempo_counter; player_host_channel->row = old_row; } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) { const uint16_t note = player_host_channel->instr_note; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT; if ((int8_t) note < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } } else { const AVSequencerInstrument *const instrument = player_host_channel->instrument; AVSequencerPlayerChannel *new_player_channel; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, note / 12, note % 12, channel))) player_channel = new_player_channel; player_channel->volume = player_host_channel->sample_note; player_channel->sub_volume = 0; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample = player_host_channel->sample; const uint32_t frequency = (uint32_t) player_host_channel->instrument; uint32_t i; uint16_t virtual_channel; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE; player_host_channel->dct = 0; player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; player_host_channel->finetune = sample->finetune; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *) &virtual_channel); sample = player_host_channel->sample; player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_host_channel->instrument = NULL; player_channel->sample = sample; player_channel->frequency = frequency; player_channel->volume = player_host_channel->instr_note; player_channel->sub_volume = 0; player_host_channel->instr_note = 0; init_new_instrument(avctx, player_host_channel, player_channel); i = -1; while (++i < module->instruments) { uint16_t smp = -1; if (!(instrument = module->instrument_list[i])) continue; while (++smp < instrument->samples) { if (!(sample = instrument->sample_list[smp])) continue; if (sample == player_channel->sample) { player_host_channel->instrument = instrument; goto instrument_found; } } } instrument_found: player_channel->instrument = player_host_channel->instrument; init_new_sample(avctx, player_host_channel, player_channel); } if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { do { process_row(avctx, player_host_channel, player_channel, channel); get_effects(avctx, player_host_channel, player_channel, channel); if (player_channel->host_channel == channel) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO)) { const int32_t slide_value = player_host_channel->vibrato_slide; player_host_channel->vibrato_slide = 0; player_channel->frequency -= slide_value; } if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO)) { int16_t slide_value = player_host_channel->tremolo_slide; player_host_channel->tremolo_slide = 0; if ((int16_t) (slide_value = (player_channel->volume - slide_value)) < 0) slide_value = 0; if (slide_value > 255) slide_value = 255; player_channel->volume = slide_value; } } } while (get_note(avctx, player_host_channel, player_channel, channel)); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { player_channel = avctx->player_channel + player_host_channel->virtual_channel; run_effects(avctx, player_host_channel, player_channel, channel); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); virtual_channel = 0; channel = 0; player_channel = avctx->player_channel; do { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { const AVSequencerSample *sample; AVSequencerPlayerEnvelope *player_envelope; uint32_t frequency, host_volume, virtual_volume; uint32_t auto_vibrato_depth, auto_vibrato_count; int32_t auto_vibrato_value; uint16_t flags, slide_envelope_value; int16_t panning, abs_panning, panning_envelope_value; player_host_channel = avctx->player_host_channel + player_channel->host_channel; player_envelope = &player_channel->vol_env; if (player_envelope->tempo) { const uint16_t volume = run_envelope(avctx, player_envelope, 1, -0x8000); if (!player_envelope->tempo) { if (!(volume >> 8)) goto turn_note_off; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } run_envelope(avctx, &player_channel->pan_env, 1, 0); slide_envelope_value = run_envelope(avctx, &player_channel->slide_env, 1, 0); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency += player_channel->slide_env_freq; if ((frequency = player_channel->frequency)) { if ((int16_t) slide_envelope_value < 0) { slide_envelope_value = -slide_envelope_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) frequency = linear_slide_down(avctx, player_channel, frequency, slide_envelope_value); else frequency = amiga_slide_down(player_channel, frequency, slide_envelope_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) { frequency = linear_slide_up(avctx, player_channel, frequency, slide_envelope_value); } else { frequency = amiga_slide_up(player_channel, frequency, slide_envelope_value); } player_channel->slide_env_freq += old_frequency - frequency; } } else { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_envelope_frequency, old_frequency; int16_t octave, note; const int16_t slide_note = (int16_t) slide_envelope_value >> 8; int32_t finetune = slide_envelope_value & 0xFF; octave = slide_note / 12; note = slide_note % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (finetune * (int32_t) next_frequency) >> 8; slide_envelope_frequency = player_channel->slide_env_freq; old_frequency = player_channel->frequency; slide_envelope_frequency += old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_envelope_frequency) >> (24 - octave); player_channel->slide_env_freq += old_frequency - frequency; } if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_FADING) { int32_t fade_out = (uint32_t) player_channel->fade_out_count; if ((fade_out -= (int32_t) player_channel->fade_out) <= 0) goto turn_note_off; player_channel->fade_out_count = fade_out; } auto_vibrato_value = run_envelope(avctx, &player_channel->auto_vib_env, player_channel->auto_vibrato_rate, 0); auto_vibrato_depth = player_channel->auto_vibrato_depth << 8; auto_vibrato_count = (uint32_t) player_channel->auto_vibrato_count + player_channel->auto_vibrato_sweep; if (auto_vibrato_count > auto_vibrato_depth) auto_vibrato_count = auto_vibrato_depth; player_channel->auto_vibrato_count = auto_vibrato_count; auto_vibrato_count >>= 8; if ((auto_vibrato_value *= (int32_t) -auto_vibrato_count)) { uint32_t old_frequency = player_channel->frequency; auto_vibrato_value >>= 7 - 2; player_channel->frequency -= player_channel->auto_vibrato_freq; if ((frequency = player_channel->frequency)) { if (auto_vibrato_value < 0) { auto_vibrato_value = -auto_vibrato_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) frequency = linear_slide_up(avctx, player_channel, frequency, auto_vibrato_value); else frequency = amiga_slide_up(player_channel, frequency, auto_vibrato_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) { frequency = linear_slide_down(avctx, player_channel, frequency, auto_vibrato_value); } else { frequency = amiga_slide_down(player_channel, frequency, auto_vibrato_value); } player_channel->auto_vibrato_freq -= old_frequency - frequency; } } if ((sample = player_channel->sample) && sample->synth) { if (!execute_synth(avctx, player_host_channel, player_channel, channel, 0)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 1)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 2)) goto turn_note_off; if (!execute_synth(avctx, player_host_channel, player_channel, channel, 3)) goto turn_note_off; } if ((!player_channel->mixer.data || !player_channel->mixer.bits_per_sample) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { player_channel->mixer.pos = 0; player_channel->mixer.len = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.data = (int16_t *) &empty_waveform; player_channel->mixer.repeat_start = 0; player_channel->mixer.repeat_length = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.repeat_count = 0; player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = (sizeof (empty_waveform[0]) * 8); diff --git a/libavsequencer/player.h b/libavsequencer/player.h index f8c5a7d..ccb96cd 100644 --- a/libavsequencer/player.h +++ b/libavsequencer/player.h @@ -1041,1009 +1041,1019 @@ typedef struct AVSequencerPlayerHostChannel { track volume slide up effect was not used yet during playback. */ uint16_t fine_trk_vol_slide_up; /** Current fine track volume slide down value or 0 if the fine track volume slide down effect was not used yet during playback. */ uint16_t fine_trk_vol_slide_dn; /** Current track volume slide to slide or 0 if the track volume slide to effect was not used yet during playback. */ uint16_t track_vol_slide_to_slide; /** Current track volume slide to volume level or 0 if the track volume slide to effect was not used yet during playback. */ uint8_t track_vol_slide_to_volume; /** Current track sub-volume slide to track volume level or 0 if the track volume slide to effect was not used yet during playback. This is basically track volume divided by 256, but the track sub-volume does not take account into actual mixer output. */ uint8_t track_vol_slide_to_sub_volume; /** Current track tremolo volume level relative to played sample volume to be able to undo the previous track tremolo volume changes or 0 if the track tremolo effect was not used yet during playback. */ int16_t track_trem_slide; /** Current track tremolo depth value or 0 if the track tremolo effect was not used yet during playback. */ int8_t track_trem_depth; /** Current track tremolo rate value or 0 if the track tremolo effect was not used yet during playback. */ uint8_t track_trem_rate; /** Current panning slide left value or 0 if the panning slide left effect was not used yet during playback. */ uint16_t pan_slide_left; /** Current panning slide right value or 0 if the panning slide right effect was not used yet during playback. */ uint16_t pan_slide_right; /** Current fine panning slide left value or 0 if the fine panning slide left effect was not used yet during playback. */ uint16_t fine_pan_slide_left; /** Current fine panning slide right value or 0 if the fine panning slide right effect was not used yet during playback. */ uint16_t fine_pan_slide_right; /** Current panning slide to slide or 0 if the panning slide to effect was not used yet during playback. */ int16_t panning_slide_to_slide; /** Current panning slide to panning position or 0 if the panning slide to effect was not used yet during playback. */ int8_t panning_slide_to_panning; /** Current sub-panning slide to panning position or 0 if the panning slide to effect was not used yet during playback. This is basically panning divided by 256, but the sub-panning does not take account into actual mixer output. */ uint8_t panning_slide_to_sub_panning; /** Current pannolo (panbrello) panning position relative to played sample panning to be able to undo the previous pannolo panning changes or 0 if the pannolo effect was not used yet during playback. */ int16_t pannolo_slide; /** Current pannolo (panbrello) depth value or 0 if the pannolo effect was not used yet during playback. */ int8_t pannolo_depth; /** Current pannolo (panbrello) rate value or 0 if the pannolo effect was not used yet during playback. */ uint8_t pannolo_rate; /** Current track panning slide left value or 0 if the track panning slide left effect was not used yet during playback. */ uint16_t track_pan_slide_left; /** Current track panning slide right value or 0 if the track panning slide right effect was not used yet during playback. */ uint16_t track_pan_slide_right; /** Current fine track panning slide left value or 0 if the fine track panning slide left effect was not used yet during playback. */ uint16_t fine_trk_pan_sld_left; /** Current fine track panning slide right value or 0 if the fine track panning slide right effect was not used yet during playback. */ uint16_t fine_trk_pan_sld_right; /** Current track panning slide to slide or 0 if the track panning slide to effect was not used yet during playback. */ int16_t track_pan_slide_to_slide; /** Current track panning slide to panning position or 0 if the track panning slide to effect was not used yet during playback. */ int8_t track_pan_slide_to_panning; /** Current track sub-panning slide to track panning position or 0 if the track panning slide to effect was not used yet during playback. This is basically track panning divided by 256, but the sub-panning does not take account into actual mixer output. */ uint8_t track_pan_slide_to_sub_panning; /** Current track pannolo (panbrello) panning position relative to played track panning to be able to undo the previous track pannolo panning changes or 0 if the track pannolo effect was not used yet during playback. */ int16_t track_pan_slide; /** Current track pannolo (panbrello) depth value or 0 if the track pannolo effect was not used yet during playback. */ int8_t track_pan_depth; /** Current track pannolo (panbrello) rate value or 0 if the track pannolo effect was not used yet during playback. */ uint8_t track_pan_rate; /** Current pattern break new row mumber or 0 if the pattern break effect was not used yet during playback. */ uint16_t break_row; /** Current position jump new order list entry mumber or 0 if the position jump effect was not used yet during playback. */ uint16_t pos_jump; /** Current change pattern target track mumber or 0 if the change pattern effect was not used yet during playback. */ uint16_t chg_pattern; /** Current pattern delay tick count or 0 if the pattern delay effect was not used yet during playback. */ uint16_t pattern_delay_count; /** Current pattern delay in number of ticks or 0 if the pattern delay effect was not used yet during playback. */ uint16_t pattern_delay; /** Current pattern loop used stack depth, i.e. number of nested loops or 0 if the pattern loop effect was not used yet during playback. */ uint16_t pattern_loop_depth; /** Current GoSub order list entry number or 0 if the GoSub effect was not used yet during playback. */ uint16_t gosub; /** Current GoSub used stack depth, i.e. number of nested order list entry calls or 0 if the GoSub effect was not used yet during playback. */ uint16_t gosub_depth; /** Current foreground virtual channel number, i.e. the virtual channel number which was allocated by the instrument currently playing and is still under direct control (can be manipulated using effect commands) or 0 if the virtual channel is moved to background by the NNA (new note action) mechanism. */ uint16_t virtual_channel; /** Current total amount of virtual channels allocated by this host channel including both the foreground channel and all the background channels. */ uint16_t virtual_channels; /** Current new transpose value in semitones or 0 if the set transpose effect was not used yet during playback. */ int8_t transpose; /** Current new finetune value in 1/128th of a semitone or 0 if the set transpose effect was not used yet during playback. */ int8_t trans_finetune; /** Current kind of envelope to be changed by the envelope control command or 0 if the envelope control effect was not used yet during playback. */ uint8_t env_ctrl_kind; /** Current type of envelope to be changed by the envelope control command or 0 if the envelope control effect was not used yet during playback. */ uint8_t env_ctrl_change; /** Current envelope control value or 0 if the envelope control effect was not used yet during playback. */ uint16_t env_ctrl; /** Current synth control number of subsequent items to be changed or 0 if the synth control effect was not used yet during playback. */ uint8_t synth_ctrl_count; /** Current synth control first item to be changed or 0 if the synth control effect was not used yet during playback. */ uint8_t synth_ctrl_change; /** Current synth control value or 0 if the synth control effect was not used yet during playback. */ uint16_t synth_ctrl; /** Current duplicate check type (DCT) value of the foreground instrument currently playing back or the instrument value if the NNA control effect was not used yet during playback. */ uint8_t dct; /** Current duplicate note action (DNA) value of the foreground instrument currently playing back or the instrument value if the NNA control effect was not used yet during playback. */ uint8_t dna; /** Current new note action (NNA) value of the foreground instrument currently playing back or the instrument value if the NNA control effect was not used yet during playback. */ uint8_t nna; /** Current channel control flags which decide how note related effects affect volume and panning, etc. and how non-note related effects affect pattern loops and breaks, etc. */ uint8_t ch_control_flags; /** Current channel control type which decides the channels affected by the channel control command or 0 if the channel control effect was not used yet during playback. */ uint8_t ch_control_type; /** Current channel control mode which decides the control scope by the channel control command or 0 if the channel control effect was not used yet during playback. */ uint8_t ch_control_mode; /** Current channel control affect which decide how note related effects affect volume and panning, etc. and how non-note related effects affect pattern loops and breaks, etc. */ uint8_t ch_control_affect; /** Current channel number to be controlled for normal single channel control mode or 0 if the channel control effect was not used yet during playback. */ uint8_t ch_control_channel; /** Current effect channel left value or 0 if the slide effect channel left effect was not used yet during playback. */ uint8_t slide_fx_ch_left; /** Current effect channel right value or 0 if the slide effect channel right effect was not used yet during playback. */ uint8_t slide_fx_ch_right; /** Current fine effect channel left value or 0 if the fine slide effect channel left effect was not used yet during playback. */ uint8_t fine_slide_fx_ch_left; /** Current fine effect channel right value or 0 if the fine slide effect channel right effect was not used yet during playback. */ uint8_t fine_slide_fx_ch_right; /** Current slide effect channel to value or 0 if the slide effect channel to effect was not used yet during playback. */ uint8_t slide_fx_channel_to; /** Current slide effect target channel or 0 if the slide effect channel to effect was not used yet during playback. */ uint8_t slide_fx_channel_to_channel; /** Current channolo channel number relative to played channel to be able to undo the previous channolo changes or 0 if the channolo effect was not used yet during playback. */ int16_t channolo_channel; /** Current channolo depth value or 0 if the channolo effect was not used yet during playback. */ int8_t channolo_depth; /** Current channolo rate value or 0 if the channolo effect was not used yet during playback. */ uint8_t channolo_rate; /** Current player vibrato envelope for the current host channel. */ AVSequencerPlayerEnvelope vibrato_env; /** Current player tremolo envelope for the current host channel. */ AVSequencerPlayerEnvelope tremolo_env; /** Current player pannolo / panbrello envelope for the current host channel. */ AVSequencerPlayerEnvelope pannolo_env; /** Current player channolo envelope for the current host channel. */ AVSequencerPlayerEnvelope channolo_env; /** Current player arpeggio definition envelope for the current host channel. */ AVSequencerPlayerEnvelope arpepggio_env; /** Current player track tremolo envelope for the current host channel. */ AVSequencerPlayerEnvelope track_trem_env; /** Current player track pannolo / panbrello envelope for the current host channel. */ AVSequencerPlayerEnvelope track_pan_env; /** Pointer to the previous volume envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_volume_env; /** Pointer to the previous panning (panbrello) envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_panning_env; /** Pointer to the previous slide envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_slide_env; /** Pointer to the previous envelope data interpreted as resonance filter control or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_resonance_env; /** Pointer to the previous auto vibrato envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_auto_vib_env; /** Pointer to the previous auto tremolo envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_auto_trem_env; /** Pointer to the previous auto pannolo (panbrello) envelope which was played by this host channel or NULL if there was no previous envelope. */ const AVSequencerEnvelope *prev_auto_pan_env; /** Array (of size waveforms) of pointers containing attached waveforms used by this host channel. */ AVSequencerSynthWave *const *waveform_list; /** Number of attached waveforms used by this host channel. */ uint16_t waveforms; /** Pointer to player synth sound definition for the current host channel for obtaining the synth sound code. */ const AVSequencerSynth *synth; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code or 0 if the current sample does not use synth sound. */ uint16_t entry_pos[4]; /** Current sustain entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code. This will position jump the code to the target line number of a key off note is pressed or 0 if the current sample does not use synth sound. */ uint16_t sustain_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when NNA has been triggered. This allows a complete custom new note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t nna_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when DNA has been triggered. This allows a complete custom duplicate note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t dna_pos[4]; /** Initial contents of the 16 variable registers (v0-v15) or 0 if the current sample does not use synth sound. */ uint16_t variable[16]; /** Current status of volume [0], panning [1], slide [2] and slide [3] variable condition status register or 0 if the current sample does not use synth sound. */ uint16_t cond_var[4]; /** Bit numbers for the controlled channels from 0-255 where the first byte determines channel numbers 0-7, the second byte 8-15 and so on. All values are zero if the channel control effect was not used yet during playback. */ uint8_t control_channels[256/8]; /** Bit numbers for all used effects from the beginning of song playback ranging from 0-127 where the first byte determines channel numbers 0-7, the second byte 8-15 and so on. */ uint8_t effects_used[128/8]; } AVSequencerPlayerHostChannel; /** AVSequencerPlayerChannel->flags bitfield. */ enum AVSequencerPlayerChannelFlags { AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN = 0x0001, ///< Sustain triggered, i.e. release sustain loop points AVSEQ_PLAYER_CHANNEL_FLAG_FADING = 0x0002, ///< Current virtual channel is fading out AVSEQ_PLAYER_CHANNEL_FLAG_DECAY = 0x0004, ///< Note decay action is running AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN = 0x0008, ///< Virtual channel uses track panning AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN = 0x0010, ///< Use surround mode for sample panning AVSEQ_PLAYER_CHANNEL_FLAG_GLOBAL_SUR_PAN = 0x0020, ///< Use surround mode for global panning AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND = 0x0040, ///< Use surround sound output for this virtual channel AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND = 0x0080, ///< Virtual channel is put into background, i.e. no more direct control (NNA) AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV = 0x0100, ///< Values of slide envelope will be portamento slides instead of a transpose and finetune pair AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV = 0x0200, ///< Use linear frequency table instead of Amiga for slide envelope in portamento mode AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB = 0x0400, ///< Use linear frequency table instead of Amiga for auto vibrato AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED = 0x8000, ///< Mark this virtual channel for allocation without playback }; /** AVSequencerPlayerChannel->cond_var bitfield. */ enum AVSequencerPlayerChannelCondVar { AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY = 0x01, ///< Carry (C) bit for volume condition variable AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW = 0x02, ///< Overflow (V) bit for volume condition variable AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO = 0x04, ///< Zero (Z) bit for volume condition variable AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE = 0x08, ///< Negative (N) bit for volume condition variable AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND = 0x10, ///< Extend (X) bit for volume condition variable }; /** AVSequencerPlayerChannel->use_nna_flags bitfield. */ enum AVSequencerPlayerChannelUseNNAFlags { AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_NNA = 0x01, ///< Use NNA trigger entry field for volume AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_NNA = 0x02, ///< Use NNA trigger entry field for panning AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_NNA = 0x04, ///< Use NNA trigger entry field for slide AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_NNA = 0x08, ///< Use NNA trigger entry field for special AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA = 0x10, ///< Use NNA trigger entry field for volume AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA = 0x20, ///< Use NNA trigger entry field for panning AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA = 0x40, ///< Use NNA trigger entry field for slide AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA = 0x80, ///< Use NNA trigger entry field for special }; /** AVSequencerPlayerChannel->use_sustain_flags bitfield. */ enum AVSequencerPlayerChannelUseSustainFlags { AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME = 0x01, ///< Use sustain entry position field for volume AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING = 0x02, ///< Use sustain entry position field for panning AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE = 0x04, ///< Use sustain entry position field for slide AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL = 0x08, ///< Use sustain entry position field for special AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME_KEEP = 0x10, ///< Keep sustain entry position for volume AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING_KEEP = 0x20, ///< Keep sustain entry position for panning AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE_KEEP = 0x40, ///< Keep sustain entry position for slide AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL_KEEP = 0x80, ///< Keep sustain entry position for special }; /** AVSequencerPlayerChannel->synth_flags bitfield. */ enum AVSequencerPlayerChannelSynthFlags { AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_VOLUME = 0x0001, ///< Volume handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_PANNING = 0x0002, ///< Panning handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_SLIDE = 0x0004, ///< Slide handling code is running KILL AVSEQ_PLAYER_CHANNEL_SYNTH_FLAG_KILL_SPECIAL = 0x0008, ///< Special handling code is running KILL }; /** * Player virtual channel data structure used by playback engine for * processing the virtual channels which are the true internal * channels associated by the tracks taking the new note actions * (NNAs) into account so one host channel can have none to multiple * virtual channels. This also contains the synth sound processing * stuff since these operate mostly on virtual channels. This * structure is actually for one virtual channel and therefore * actually pointed as an array with size of number of virtual * channels. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerChannel { /** Mixer channel data responsible for this virtual channel. This will be passed to the actual mixer which calculates the final audio data. */ AVMixerChannel mixer; /** Pointer to player instrument definition for the current virtual channel for obtaining instrument stuff. */ const AVSequencerInstrument *instrument; /** Pointer to player sound sample definition for the current virtual channel for obtaining sample data. */ const AVSequencerSample *sample; /** Current output frequency in Hz of currently playing sample or waveform. This will be forwarded after relative pitch scaling to the mixer channel data. */ uint32_t frequency; /** Current sample volume of currently playing sample or waveform for this virtual channel. */ uint8_t volume; /** Current sample sub-volume of currently playing sample or waveform. This is basically volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t sub_volume; - /** Current instrument global volume of currently playing - instrument being played by this virtual channel. */ + /** Current instrument global volume multiplied with current + sample global volume of currently playing instrument + being played by this virtual channel. */ uint16_t instr_volume; /** Current sample panning position of currently playing sample or waveform for this virtual channel. */ int8_t panning; /** Current sample sub-panning of currently playing sample or waveform. This is basically panning divided by 256, but the sub-panning doesn't account into actual mixer output. */ uint8_t sub_panning; /** Current final volume level of currently playing sample or waveform for this virtual channel as it will be forwarded to the mixer channel data. */ uint8_t final_volume; /** Current final panning of currently playing sample or waveform for this virtual channel as it will be forwarded to the mixer channel data. */ int8_t final_panning; /** Current sample global volume of currently playing sample or waveform for this virtual channel. */ uint8_t global_volume; /** Current sample global sub-volume of currently playing sample or waveform. This is basically global volume divided by 256, but the sub-volume doesn't account into actual mixer output. */ uint8_t global_sub_volume; /** Current sample global panning position of currently playing sample or waveform for this virtual channel. */ int8_t global_panning; /** Current sample global sub-panning of currently playing sample or waveform. This is basically global panning divided by 256, but sub-panning doesn't account into actual mixer output. */ uint8_t global_sub_panning; + /** Current instrument global volume of currently playing + instrument for this virtual channel. */ + uint8_t global_instr_volume; + + /** Current random note swing in semi-tones. This value will + cause a flip between each play of this instrument making it + sounding more natural. */ + uint8_t note_swing; + /** Current random volume swing in 1/256th steps (i.e. 256 means 100%). The volume will vibrate randomnessly around that volume percentage and make the instrument sound more like a naturally played one. */ uint16_t volume_swing; /** Current random panning swing in 1/256th steps (i.e. 256 means 100%). This will cause the stereo position to vary a bit each instrument play to make it sound more like a naturally played one. */ uint16_t panning_swing; /** Current random pitch swing in 1/65536th steps, i.e. 65536 means 100%. This will cause the stereo position to vary a bit each instrument play to make it sound more like a naturally played one. */ uint32_t pitch_swing; /** Current host channel to which this virtual channel is mapped to, i.e. the creator of this virtual channel. */ uint16_t host_channel; /** Player virtual channel flags. This stores certain information about the current virtual channel based upon the host channel which allocated this virtual channel. The virtual channels are allocated according to the new note action (NNA) mechanism. */ uint16_t flags; /** Current player volume envelope for the current virtual channel. */ AVSequencerPlayerEnvelope vol_env; /** Current player panning envelope for the current virtual channel. */ AVSequencerPlayerEnvelope pan_env; /** Current player slide envelope for the current virtual channel. */ AVSequencerPlayerEnvelope slide_env; /** Pointer to player envelope data interpreted as resonance filter for the current virtual channel. */ AVSequencerPlayerEnvelope resonance_env; /** Current player auto vibrato envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_vib_env; /** Current player auto tremolo envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_trem_env; /** Current player auto pannolo / panbrello envelope for the current virtual channel. */ AVSequencerPlayerEnvelope auto_pan_env; /** Current slide envelope relative to played sample frequency to be able to undo the previous slide envelope frequency. */ int32_t slide_env_freq; /** Current auto vibrato frequency relative to played sample frequency to be able to undo the previous auto vibrato frequency changes. */ int32_t auto_vibrato_freq; /** Current auto tremolo volume level relative to played sample volume to be able to undo the previous auto tremolo volume changes. */ int16_t auto_tremolo_vol; /** Current auto pannolo (panbrello) panning position relative to played sample panning to be able to undo the previous auto pannolo panning changes. */ int16_t auto_pannolo_pan; /** Current number of tick for auto vibrato incremented by the auto vibrato sweep rate. */ uint16_t auto_vibrato_count; /** Current number of tick for auto tremolo incremented by the auto tremolo sweep rate. */ uint16_t auto_tremolo_count; /** Current number of tick for auto pannolo (panbrello) incremented by the auto pannolo sweep rate. */ uint16_t auto_pannolo_count; /** Current fade out value which is subtracted each tick with to fade out count value until zero is reached or 0 if fade out is disabled for this virtual channel. */ uint16_t fade_out; /** Current fade out count value where 65535 is the initial value (full volume level) which is subtracted each tick with the fade out value until zero is reached, when the note will be turned off. */ uint16_t fade_out_count; /** Current pitch panning separation. */ int16_t pitch_pan_separation; /** Current pitch panning center (0 is C-0, 1 is C#1, 12 is C-1, 13 is C#1, 24 is C-2, 36 is C-3 and so on. */ uint8_t pitch_pan_center; /** Current decay action when decay is off. */ uint8_t dca; /** Hold value. */ uint16_t hold; /** Decay value. */ uint16_t decay; /** Current auto vibrato sweep. */ uint16_t auto_vibrato_sweep; /** Current auto tremolo sweep. */ uint16_t auto_tremolo_sweep; /** Current auto pannolo (panbrello) sweep. */ - uint16_t auto_pan_sweep; + uint16_t auto_pannolo_sweep; /** Current auto vibrato depth. */ uint8_t auto_vibrato_depth; /** Current auto vibrato rate (speed). */ uint8_t auto_vibrato_rate; /** Current auto tremolo depth. */ uint8_t auto_tremolo_depth; /** Current auto tremolo rate (speed). */ uint8_t auto_tremolo_rate; /** Current auto pannolo (panbrello) depth. */ - uint8_t auto_pan_depth; + uint8_t auto_pannolo_depth; /** Current auto pannolo (panbrello) rate. */ - uint8_t auto_pan_rate; + uint8_t auto_pannolo_rate; /** Current instrument note being played (after applying current instrument transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t instr_note; /** Current sample note being played (after applying current sample transpose) by the formula: current octave * 12 + current note where C-0 equals to one. */ uint8_t sample_note; /** Array (of size waveforms) of pointers containing attached waveforms used by this virtual channel. */ AVSequencerSynthWave *const *waveform_list; /** Number of attached waveforms used by this virtual channel. */ uint16_t waveforms; /** Pointer to sequencer sample synth sound currently being played by this virtual channel for obtaining the synth sound code. */ const AVSequencerSynth *synth; /** Pointer to current sample data waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *sample_waveform; /** Pointer to current vibrato waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *vibrato_waveform; /** Pointer to current tremolo waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *tremolo_waveform; /** Pointer to current pannolo (panbrello) waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *pannolo_waveform; /** Pointer to current arpeggio data waveform used by the synth sound currently being played by this virtual channel. */ const AVSequencerSynthWave *arpeggio_waveform; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code or 0 if the current sample does not use synth sound. */ uint16_t entry_pos[4]; /** Current sustain entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code. This will position jump the code to the target line number of a key off note is pressed or 0 if the current sample does not use synth sound. */ uint16_t sustain_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when NNA has been triggered. This allows a complete custom new note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t nna_pos[4]; /** Current entry position (line number) of volume [0], panning [1], slide [2] and special [3] handling code when DNA has been triggered. This allows a complete custom duplicate note action to be defined or 0 if the current sample does not use synth sound. */ uint16_t dna_pos[4]; /** Current contents of the 16 variable registers (v0-v15). */ uint16_t variable[16]; /** Current status of volume [0], panning [1], slide [2] and special [3] variable condition status register or 0 if the current sample does not use synth sound. */ uint16_t cond_var[4]; /** Current usage of NNA trigger entry fields. This will run custom synth sound code execution on a NNA trigger. */ uint8_t use_nna_flags; /** Current usage of sustain entry position fields. This will run custom synth sound code execution on a note off trigger. */ uint8_t use_sustain_flags; /** Current final note being played (after applying all transpose values, etc.) by the formula: current octave * 12 + current note where C-0 is represented with a value zero. */ int16_t final_note; /** Current sample finetune value in 1/128th of a semitone. */ int8_t finetune; /** Current STOP synth sound instruction forbid / permit mask or 0 if the current sample does not use synth sound. */ uint8_t stop_forbid_mask; /** Current waveform position in samples of the VIBRATO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t vibrato_pos; /** Current waveform position in samples of the TREMOLO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t tremolo_pos; /** Current waveform position in samples of the PANNOLO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t pannolo_pos; /** Current waveform position in samples of the ARPEGIO synth sound instruction or 0 if the current sample does not use synth sound. */ uint16_t arpeggio_pos; /** Current player channel synth sound flags. The indicate certain status flags for some synth code instructions. Currently they are only defined for the KILL instruction. */ uint16_t synth_flags; /** Current volume [0], panning [1], slide [2] and special [3] KILL count in number of ticks or 0 if the current sample does not use synth sound. */ uint16_t kill_count[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT count in number of ticks or 0 if the current sample does not use synth sound. */ uint16_t wait_count[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT line number to be reached to continue execution or 0 if the current sample does not use synth sound. */ uint16_t wait_line[4]; /** Current volume [0], panning [1], slide [2] and special [3] WAIT type (0 is WAITVOL, 1 is WAITPAN, 2 is WAITSLD and 3 is WAITSPC) which has to reach the specified target line number before to continue execution or 0 if the current sample does not use synth sound. */ uint8_t wait_type[4]; /** Current PORTAUP synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t porta_up; /** Current PORTADN synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t porta_dn; /** Current PORTAUP and PORTADN synth sound instruction total value, i.e. all PORTAUP and PORTADN instructions added together or 0 if the current sample does not use synth sound. */ int32_t portamento; /** Current VIBRATO synth sound instruction frequency relative to played sample frequency to be able to undo the previous vibrato frequency changes or 0 if the current sample does not use synth sound. */ int32_t vibrato_slide; /** Current VIBRATO synth sound instruction rate value or 0 if the current sample does not use synth sound. */ uint16_t vibrato_rate; /** Current VIBRATO synth sound instruction depth value or 0 if the current sample does not use synth sound. */ int16_t vibrato_depth; /** Current ARPEGIO synth sound instruction frequency relative to played sample frequency to be able to undo the previous arpeggio frequency changes or 0 if the current sample does not use synth sound. */ int32_t arpeggio_slide; /** Current ARPEGIO synth sound instruction speed value or 0 if the current sample does not use synth sound. */ uint16_t arpeggio_speed; /** Current ARPEGIO synth sound instruction transpose value or 0 if the current sample does not use synth sound. */ int8_t arpeggio_transpose; /** Current ARPEGIO synth sound instruction finetuning value in 1/128th of a semitone or 0 if the current sample does not use synth sound. */ int8_t arpeggio_finetune; /** Current VOLSLUP synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t vol_sl_up; /** Current VOLSLDN synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t vol_sl_dn; /** Current TREMOLO synth sound instruction volume level relative to played sample volume to be able to undo the previous tremolo volume changes or 0 if the current sample does not use synth sound. */ int16_t tremolo_slide; /** Current TREMOLO synth sound instruction depth value or 0 if the current sample does not use synth sound. */ int16_t tremolo_depth; /** Current TREMOLO synth sound instruction rate value or 0 if the current sample does not use synth sound. */ uint16_t tremolo_rate; /** Current PANLEFT synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t pan_sl_left; /** Current PANRIGHT synth sound instruction memory or 0 if the current sample does not use synth sound. */ uint16_t pan_sl_right; /** Current PANNOLO synth sound instruction relative slide value or 0 if the current sample does not use synth sound. */ int16_t pannolo_slide; /** Current PANNOLO synth sound instruction depth or 0 if the current sample does not use synth sound. */ int16_t pannolo_depth; /** Current PANNOLO synth sound instruction rate or 0 if the current sample does not use synth sound. */ uint16_t pannolo_rate; } AVSequencerPlayerChannel; #include "libavsequencer/avsequencer.h" /** AVSequencerPlayerEffects->flags bitfield. */ enum AVSequencerPlayerEffectsFlags { AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW = 0x80, ///< Effect will be executed during the whole row instead of only once }; typedef struct AVSequencerPlayerEffects { /** Function pointer to the actual effect to be executed for this effect. Can be NULL if this effect number is unused. This structure is actually for one effect and there actually pointed as an array with size of number of total effects. */ void (*effect_func)(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const unsigned fx_byte, uint16_t data_word); /** Function pointer for pre-pattern evaluation. Some effects require a pre-initialization stage. Can be NULL if the effect number either is not used or the effect does not require a pre-initialization stage. */ void (*pre_pattern_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); /** Function pointer for parameter checking for an effect. Can be NULL if the effect number either is not used or the effect does not require pre-checking. */ void (*check_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); /** Special flags for this effect, this currently defines if the effect is executed during the whole row each tick or just only once per row. */ uint8_t flags; /** Logical AND filter mask for the channel control command filtering the affected channel. */ uint8_t and_mask_ctrl; /** Standard execution tick when this effect starts to be executed and there is no execute effect command issued which is in most case tick 0 (immediately) or 1 (skip first tick at row). */ uint16_t std_exec_tick; } AVSequencerPlayerEffects; /** AVSequencerPlayerHook->flags bitfield. */ enum AVSequencerPlayerHookFlags { AVSEQ_PLAYER_HOOK_FLAG_SONG_END = 0x01, ///< Hook is only called when song end is being detected instead of each tick AVSEQ_PLAYER_HOOK_FLAG_BEGINNING = 0x02, ///< Hook is called before executing playback code instead of the end }; /** * Playback handler hook for allowing developers to execute customized * code in the playback handler under certain conditions. Currently * the hook can either be called once at song end found or each tick, * as well as before execution of the playback handler or after it. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerPlayerHook { /** Special flags for the hook which decide hook call time and purpose. */ int8_t flags; /** The actual hook function to be called which gets passed the associated AVSequencerContext. */ void (*hook_func)(AVSequencerContext *avctx, void *hook_data, uint64_t hook_len); /** The actual hook data to be passed to the hook function which also gets passed the associated AVSequencerContext and the module and sub-song currently processed (i.e. triggered the hook). */ void *hook_data; /** Size of the hook data passed to the hook function which gets passed the associated AVSequencerContext and the module and sub-song currently processed (i.e. triggered the hook). */ uint64_t hook_len; } AVSequencerPlayerHook; #endif /* AVSEQUENCER_PLAYER_H */ diff --git a/libavsequencer/track.h b/libavsequencer/track.h index 1a74111..8aa1d27 100644 --- a/libavsequencer/track.h +++ b/libavsequencer/track.h @@ -316,1081 +316,1083 @@ enum AVSequencerTrackEffectCommand { AVSEQ_TRACK_EFFECT_CMD_INVERT_LOOP = 0x1B, /** Execute command effect at tick: Data word consists of a 16-bit unsigned value which represents the tick number at where the next effect will be executed. This also can be used to simulate fast slides or vibratos by putting a zero as value. */ AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX = 0x1C, /** Stop command effect at tick: Data word consists of two 8-bit pairs named xx and yy where xx represents the tick number at where to stop command effect execution and yy will be the command effect number which should be stopped. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_STOP_FX = 0x1D, /* Volume effect commands. */ /** Set volume: Data word consists of two 8-bit pairs named xx and yy where xx is the volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) and yy is the sub-volume level which allows to set 1/256th of a volume level. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME = 0x20, /** Volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx is the volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume slide up level which allows to set 1/256th of a volume slide up level. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP = 0x21, /** Volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume slide down level which allows to set 1/256th of a volume slide down level. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_DOWN = 0x22, /** Fine volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx is the volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume slide up level which allows to set 1/256th of a volume slide up level. The fine volume slide up is done only once per row (at first tick). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP = 0x23, /** Fine volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume slide down level which allows to set 1/256th of a volume slide down level. The fine volume slide down is done only once per row (at first tick). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_DOWN = 0x24, /** Volume slide to: Data word consists of two 8-bit pairs named xx and yy where xx is either the volume level (ranging either from 0x01 - 0xFE or in tracker volume mode from 0x01 - 0x3F) to slide to (the target volume desired) and yy is the sub-volume slide to level which allows to set 1/256th of a volume slide to level, 0x00 to execute the slide instead of setting it or 0xFF to execute a fine volume slide instead (only once per row). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_TO = 0x25, /** Tremolo: Data word consists of two 8-bit pairs named xx and yy where xx is the tremolo speed and yy is the tremolo depth. The tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. xx is unsigned and yy is signed. A negative tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_TREMOLO = 0x26, /** Tremolo once: Data word consists of two 8-bit pairs named xx and yy where xx is the tremolo speed and yy is the tremolo depth. The tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. The tremolo is executed only once per row, i.e. at first tick. xx is unsigned and yy is signed. A negative tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_TREMOLO_ONCE = 0x27, /** Set track volume: Data word consists of two 8-bit pairs named xx and yy where xx is the track volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) and yy is the sub-volume track level which allows to set 1/256th of a track volume level. Other volume levels are scaled with track volume. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL = 0x28, /** Track volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx is the track volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume track slide up level which allows to set 1/256th of a volume slide up level. Other volume levels are scaled with track volume. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP = 0x29, /** Track volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the track volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume track slide down level which allows to set 1/256th of a volume slide down level. Other volume levels are scaled with track volume. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_DOWN = 0x2A, /** Fine track volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx is the track volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume track slide up level which allows to set 1/256th of a volume slide up level. Other volume levels are scaled with track volume. The fine track volume slide up is done only once per row, i.e. at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP = 0x2B, /** Fine track volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the track volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume track slide down level which allows to set 1/256th of a volume slide down level. Other volume levels are scaled with track volume. The fine track volume slide down is done only once per row, i.e. at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_DN = 0x2C, /** Track volume slide to: Data word consists of two 8-bit pairs named xx and yy where xx is either the track volume level (ranging either from 0x01 - 0xFE or in tracker volume mode from 0x01 - 0x3F) to slide to (the target track volume desired) and yy is the sub-volume track slide to level which allows to set 1/256th of a track volume slide to level, 0x00 to execute the slide instead of setting it or 0xFF to execute a fine track volume slide instead (only once per row). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TVOL_SLD_TO = 0x2D, /** Track tremolo: Data word consists of two 8-bit pairs named xx and yy where xx is the track tremolo speed and yy is the track tremolo depth. The track tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. xx is unsigned and yy is signed. A negative track tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_TRK_TREMOLO = 0x2E, /** Track tremolo once: Data word consists of two 8-bit pairs named xx and yy where xx is the track tremolo speed and yy is the track tremolo depth. The track tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. The tremolo is executed only once per row, i.e. at first tick. xx is unsigned and yy is signed. A negative tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_T_TREMO_ONCE = 0x2F, /* Panning effect commands. */ /** Set panning position: Data word consists of two 8-bit pairs named xx and yy where xx is the panning position ranging from 0x00 (full stereo left left panning) to 0xFF (full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) and yy is the sub-panning position which allows to set 1/256th of a panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_PANNING = 0x30, /** Panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the panning left position level ranging from 0x00 - 0xFF and yy is the sub-panning slide left position which allows to set 1/256th of a panning slide left position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT = 0x31, /** Panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning slide right position which allows to set 1/256th of a panning slide right position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_PAN_SL_RIGHT = 0x32, /** Fine panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the panning left slide position ranging from 0x00 - 0xFF and yy is the sub-panning slide left position which allows to set 1/256th of a panning slide left position. The fine panning slide left is done only once per row, i.e. at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT = 0x33, /** Fine panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning slide right position which allows to set 1/256th of a panning slide right position. The fine panning slide right is done only once per row, i.e. at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_P_SL_RIGHT = 0x34, /** Panning slide to: Data word consists of two 8-bit pairs named xx and yy where xx is the panning position ranging from 0x01 (almost full stereo left panning) to 0xFE (almost full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) to slide to (the target stereo position desired) and yy is the sub-panning slide to position which allows to set 1/256th of a panning slide to position, 0x00 to execute the slide instead of setting it or 0xFF to do a fine panning slide instead (only once per row). Other stereo positions are scaled to track panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_PAN_SLD_TO = 0x35, /** Pannolo / Panbrello: Data word consists of two 8-bit pairs named xx and yy where xx is the pannolo speed and yy is the pannolo depth. The pannolo values are compatible with the MOD, S3M, XM and IT pannolo if an inverted pannolo envelope with a length of 64 ticks and the amplitude of 256 is used. xx is unsigned and yy is signed. A negative pannolo depth means that the pannolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_PANNOLO = 0x36, /** Pannolo / Panbrello once: Data word consists of two 8-bit pairs named xx and yy where xx is the pannolo speed and yy is the pannolo depth. The pannolo values are compatible with the MOD, S3M, XM and IT pannolo if an inverted pannolo envelope with a length of 64 ticks and the amplitude of 256 is used. The pannolo is executed only once per row, i.e. at first tick. xx is unsigned and yy is signed. A negative pannolo depth means that the pannolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_PANNOLO_ONCE = 0x37, /** Set track panning: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning position ranging from 0x00 (full stereo left panning) to 0xFF (full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) and yy is the sub-panning position which allows to set 1/256th of a track panning position. Other stereo positions are scaled to track panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN = 0x38, /** Track panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning left slide position ranging from 0x00 - 0xFF and yy is the sub-panning track slide left position which allows to set 1/256th of a panning slide left position. Other stereo positions are scaled to track panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT = 0x39, /** Track panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning track slide right position which allows to set 1/256th of a panning slide right position. Other stereo positions are scaled to track panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_RGHT = 0x3A, /** Fine track panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning left slide position ranging from 0x00 - 0xFF and yy is the sub-panning track slide left position which allows to set 1/256th of a panning slide left position. Other stereo positions are scaled to track panning position. The fine track panning slide left is done only once per row, i.e. only at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT = 0x3B, /** Fine track panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning track slide right position which allows to set 1/256th of a panning slide right position. Other stereo positions are scaled to track panning position. The fine track panning slide right is done only once per row, i.e. only at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_RGHT = 0x3C, /** Track panning slide to: Data word consists of two 8-bit pairs named xx and yy where xx is the track panning position ranging from 0x01 (almost full stereo left panning) to 0xFE (almost full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) to slide to (the target track stereo position desired) and yy is the sub-panning track slide to position which allows to set 1/256th of a track panning slide to position, 0x00 to execute the slide instead of setting it or 0xFF to do a fine track panning slide instead, i.e. execute it only once per row (first tick). Other stereo positions are scaled to track panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_TPAN_SLD_TO = 0x3D, /** Track pannolo / panbrello: Data word consists of two 8-bit pairs named xx and yy where xx is the track pannolo speed and yy is the track pannolo depth. The track pannolo values are compatible with the MOD, S3M, XM and IT pannolo if an inverted pannolo envelope with a length of 64 ticks and the amplitude of 256 is used. xx is unsigned and yy is signed. A negative track pannolo depth means that the pannolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_TRK_PANNOLO = 0x3E, /** Track pannolo / panbrello once: Data word consists of two 8-bit pairs named xx and yy where xx is the track pannolo speed and yy is the track pannolo depth. The track pannolo values are compatible with the MOD, S3M, XM and IT pannolo if an inverted pannolo envelope with a length of 64 ticks and the amplitude of 256 is used. The track pannolo is executed only once per row, i.e. at first tick. xx is unsigned and yy is signed. A negative pannolo depth means that the pannolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_TPANOLO_ONCE = 0x3F, /* Track effect commands. */ /** Set channel tempo: Data word consists of a 16-bit unsigned value which represents the number of ticks per row to change to for this track or zero for marking the song end. */ AVSEQ_TRACK_EFFECT_CMD_SET_TEMPO = 0x40, /** Set channel tempo: Data word consists of a 16-bit signed value which represents the relative number of ticks per row to add for this track. A positive value will make the song slower (adds more ticks per row) and a negative value will make it faster instead. */ AVSEQ_TRACK_EFFECT_CMD_SET_REL_TMPO = 0x41, /** Pattern break: Data word consists of a 16-bit unsigned value which represents the new row where to start next track after breaking current track. Zero is the first track. */ AVSEQ_TRACK_EFFECT_CMD_PATT_BREAK = 0x42, /** Position jump: Data word consists of a 16-bit unsigned value which represents the new position / order list number to jump to (zero being the first order list entry). The current track is cancelled immediately. */ AVSEQ_TRACK_EFFECT_CMD_POS_JUMP = 0x43, /** Relative position jump: Data word consists of a 16-bit signed value which represents the new relative position / order list number to jump to. A positive value means a forward jump and negative values represent backward jumping. */ AVSEQ_TRACK_EFFECT_CMD_REL_POS_JUMP = 0x44, /** Change pattern: Data word consists of a 16-bit unsigned value which represents the new track number where to switch to. Unlike pattern break this effect does not change the track immediately but finishes the currently track being played. */ AVSEQ_TRACK_EFFECT_CMD_CHG_PATTERN = 0x45, /** Reverse play control: Data word consists of a 16-bit unsigned value which either has the value 0xFF00 for changing playback direction to always backwards, 0x0001 for changing to always forwards and zero for inverting current playback direction. */ AVSEQ_TRACK_EFFECT_CMD_REVERSE_PLAY = 0x46, /** Pattern delay: Data word consists of a 16-bit unsigned value which determines the value of number of rows to compact to one, i.e. the row will be delayed for this track while the effects continue normal executing. */ AVSEQ_TRACK_EFFECT_CMD_PATT_DELAY = 0x47, /** Fine pattern delay: Data word consists of a 16-bit unsigned value which determines the value of number of ticks to compact delay this track, the effects continue normal executing. */ AVSEQ_TRACK_EFFECT_CMD_F_PATT_DELAY = 0x48, /** Pattern loop: Data word consists of a 16-bit unsigned value which determines determines either setting the loop mark when the value is zero which pushes the current order list / position number on the loop stack) or when using a non-zero value, it will cause to jump back to this order list entry number. If the loop stack is full, the newest loop mark will be overwritten. */ AVSEQ_TRACK_EFFECT_CMD_PATT_LOOP = 0x49, /** GoSub: Data word consists of a 16-bit unsigned value which represents the new order list entry number where to jump to. The current order list entry and track row number is pushed on the GoSub stack, if the stack is not full and continue playback at the new order list entry otherwise simply nothing happens. */ AVSEQ_TRACK_EFFECT_CMD_GOSUB = 0x4A, /** Return from GoSub: Data word consists of a 16-bit unsigned value which determines, if set to non-zero, the row number of the track number stored with the GoSub command otherwise it will continue playback at specified row number. If the GoSub stack is empty, this track will be disabled for the whole song. */ AVSEQ_TRACK_EFFECT_CMD_RETURN = 0x4B, /** Channel synchronization: Data word consists of two 8-bit pairs named xx and yy where xx is the first channel to synchronize with and yy the second channel to synchronize with. If both xx and yy are zero, it will synchronize with all channels instead, if both xx and yy are equal then only synchronize with one channel. The current channel will be halted until all synchronization is finished. Both xx and yy represent unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_CHANNEL_SYNC = 0x4C, /** Set target sub-slide to: Data word consists of two unsigned 8-bit pairs named xx and yy where xx defines the the target sub-slide types to set the sub-slide values to for having 256x more finer control which is represented by yy to as declared by the following table: xx | Meanings 0x01 | Apply sub-slide to volume 0x02 | Apply sub-slide to track volume 0x04 | Apply sub-slide to global volume 0x08 | Apply sub-slide to panning 0x10 | Apply sub-slide to track panning 0x20 | Apply sub-slide to global panning You can add these values together to set multiple target values at once, e.g. 0x11 will apply the sub-slide value to volume and track panning. */ AVSEQ_TRACK_EFFECT_CMD_SET_SUBSLIDE = 0x4D, /* Instrument, sample and synth effect commands. */ /** Sample offset high word: Data word consists of a 16-bit unsigned value which is the high word (upper 16 bits) of the target sample position to start the sample playback at. This effect does not change actually the sample position (see below). */ AVSEQ_TRACK_EFFECT_CMD_SMP_OFF_HIGH = 0x50, /** Sample offset low word: Data word consists of a 16-bit unsigned value which is the low word (lower 16 bits) of the target sample position to start the sample playback at. This effect executes the actual change and sets the sample position according to the high word value of effect 0x50 with the formula high word * 0x10000 + low word. This allows setting the sample playback start position with an accuracy of exactly one sample. */ AVSEQ_TRACK_EFFECT_CMD_SMP_OFF_LOW = 0x51, /** Set hold: Data word consists of a 16-bit unsigned value which represents the new hold count of MED-style trackers to be used. This allows resetting the hold instrument. */ AVSEQ_TRACK_EFFECT_CMD_SET_HOLD = 0x52, /** Set decay: Data word consists of a 16-bit unsigned value which contains either the decay to be set (if decay is not alread in action or the decay counter otherwise, i.e. new hold count of MED-style trackers. */ AVSEQ_TRACK_EFFECT_CMD_SET_DECAY = 0x53, /** Set transpose: Data word consists of two signed 8-bit pairs named xx and yy where xx is the new transpose and yy the new finetune value which should be applied to the new note. This command has no effect if not used in conjunction with a new note. */ AVSEQ_TRACK_EFFECT_CMD_SET_TRANSP = 0x54, /** Instrument control: Data word consists of two 8-bit pairs named xx and yy - where xx are the turn off bits and yy the turn off bits. + where xx are the turn off bits and yy the turn on bits. Bits not touched by either will be prevented from the - special instrument control changes. The table is declared as: + special instrument control changes and bits touched by + both will be flipped. The table is declared as: xx/yy | Meanings 0x01 | Apply to use sample panning bit. If set, the sample panning with be used instead of the instrument panning. 0x02 | Apply to order list is transposable bit. If this is set, the order list entry's transpose values are applied to the final note. 0x08 | Apply to use slide envelopes portamento bit. If set, slide envelope values are interpreted as portamento values instead of transpose and finetune. 0x10 | Apply to use slide envelope linear frequency bit. If this one is set, the slide envelopes will use linear frequency scaling instead of Amiga frequency scaling. 0x20 | Apply to set sample offset relative bit. If this is set, the commands 0x50 and 0x51 are applied relative to the current sample playback position instead of being absolute. 0x80 | Apply to use auto vibrato linear frequency bit. If set, the auto vibratos will use linear frequency scaling instead of the Amiga one. */ AVSEQ_TRACK_EFFECT_CMD_INS_CONTROL = 0x55, /** Instrument change: Data word consists of one upper 4-bit nibble named x and of a 12-bit value named yyy. All values are considered unsigned and the meanings of x change by declarition of the following table: x | Meanings 0 | Change instrument global volume to the lower 8 bits of yyy. 1 | Change instrument volume swing to yyy. 2 | Change instrument panning swing to yyy. - 3 | Change instrument pitch swing to to yyy in percentage. + 3 | Change instrument pitch swing to yyy in percentage. 4 | Change instrument fadeout to yyy * 0x10. 5 | Change fadeout count to yyy * 0x10 if yyy is non-zero, otherwise immediately stop the fadeout. 6 | Auto vibrato / tremolo / pannolo change. The upper 4 bits of yyy are interpreted as the exact change type which is declared by the following table: y | Meanings 0x0 | Set auto vibrato sweep to the lower 8 bits of yyy. 0x1 | Set auto vibrato depth to the lower 8 bits of yyy. 0x2 | Set auto vibrato rate to the lower 8 bits of yyy. 0x4 | Set auto tremolo sweep to the lower 8 bits of yyy. 0x5 | Set auto tremolo depth to the lower 8 bits of yyy. 0x6 | Set auto tremolo rate to the lower 8 bits of yyy. 0x8 | Set auto pannolo sweep to the lower 8 bits of yyy. 0x9 | Set auto pannolo depth to the lower 8 bits of yyy. 0xA | Set auto pannolo rate to the lower 8 bits of yyy. 7 | Set pitch panning separation to yyy. 8 | Set pitch panning center to the lower 8 bits of yyy. 9 | Set DCA (Decay Action) to either cut when yyy equals zero, keyoff if yyy equals 0x001 and fadeout for yyy being 0x002. A | Set (resonance) filter cutoff to yyy. - B | Set (resonance) filter damping to yyy. */ + B | Set (resonance) filter damping to yyy. + C | Change instrument note swing to the lower 8 bits of yyy. */ AVSEQ_TRACK_EFFECT_CMD_INS_CHANGE = 0x56, /** Synth control: Data word consists of two 8-bit pairs named xx and yy where xx the amount of following entries (see table below) are to be included into changing values, e.g. 0x0F10 would change all variable numbers since first variable starts at 0x10 and the following 15 variables are affected also, i.e. a total of 16 value changes, or zero for only changing the value(s) declared by yy with the following table which also can have the most upper bit set to indicate that the value should be set immediately by using the previous synth value (0x58) effect: yy | Meanings 0x00 | Set volume handling code position. 0x01 | Set panning handling code position. 0x02 | Set slide handling code position. 0x03 | Set special handling code position. 0x04 | Set volume sustain release position. 0x05 | Set panning sustain release position. 0x06 | Set slide sustain release position. 0x07 | Set special sustain release position. 0x08 | Set volume NNA trigger position. 0x09 | Set panning NNA trigger position. 0x0A | Set slide NNA trigger position. 0x0B | Set special NNA trigger position. 0x0C | Set volume DNA trigger position. 0x0D | Set panning DNA trigger position. 0x0E | Set slide DNA trigger position. 0x0F | Set special DNA trigger position. 0x1y | Set value of the variable number specified by the lower 4 bits of yy. 0x20 | Set volume condition variable value. 0x21 | Set panning condition variable value. 0x22 | Set slide condition variable value. 0x23 | Set special condition variable value. 0x24 | Set sample waveform. 0x25 | Set vibrato waveform. 0x26 | Set tremolo waveform. 0x27 | Set pannolo waveform. 0x28 | Set arpeggio waveform. */ AVSEQ_TRACK_EFFECT_CMD_SYNTH_CTRL = 0x57, /** Set synth value: Data word consists of a 16-bit unsigned value which contains the actual value to be set, since command 0x57 (synth control) does only set the type not the actual value (unless most upper bit is set). */ AVSEQ_TRACK_EFFECT_CMD_SET_SYN_VAL = 0x58, /** Envelope control: Data word consists of two unsigned 8-bit pairs named xx and yy where xx is the kind of envelope to be selected as declared by the following table which can have the most upper bit set to indicate that the value should be set immedately by using the previous envelope value (0x5A) effect: xx | Meanings 0x00 | Select volume envelope. 0x01 | Select panning envelope. 0x02 | Select slide envelope. 0x03 | Select vibrato envelope. 0x04 | Select tremolo envelope. 0x05 | Select pannolo envelope. 0x06 | Select channolo envelope. 0x07 | Select spenolo envelope. 0x08 | Select auto vibrato envelope. 0x09 | Select auto tremolo envelope. 0x0A | Select auto pannolo envelope. 0x0B | Select track tremolo envelope. 0x0C | Select track pannolo envelope. 0x0D | Select global tremolo envelope. 0x0E | Select global pannolo envelope. 0x0F | Select arpeggio envelope, an yy of 0x01, 0x11, 0x02 or 0x12 will not have an effect for this kind of envelope. 0x10 | Select resonance filter envelope. yy selects the envelope type of which to change the value as declared by the following table: yy | Meanings 0x00 | Set the waveform number. 0x10 | Reset envelope, no command 0x5A required. 0x01 | Set retrigger flag off, no command 0x5A required. 0x11 | Set retrigger flag on, no command 0x5A required. 0x02 | Set random flag off, no command 0x5A required. 0x12 | Set random flag on, no command 0x5A required. 0x22 | Set random delay flag off, no command 0x5A required. 0x32 | Set random delay flag on, no command 0x5A required. 0x03 | Set count and set off, no command 0x5A required. 0x13 | Set count and set on, no command 0x5A required. 0x04 | Set envelope position by tick. 0x14 | Set envelope position by node number. 0x05 | Set envelope tempo. 0x15 | Set envelope tempo relatively. 0x25 | Set fine envelope tempo (count). 0x06 | Set sustain start point. 0x07 | Set sustain end point. 0x08 | Set sustain loop count value. 0x09 | Set sustain loop counted value. 0x0A | Set loop start point. 0x1A | Set current loop start point. 0x0B | Set loop end point. 0x1B | Set current loop end point. 0x0C | Set loop count value. 0x0D | Set loop counted value. 0x0E | Set random lowest value. 0x0F | Set random highest value. */ AVSEQ_TRACK_EFFECT_CMD_ENV_CONTROL = 0x59, /** Set envelope value: Data word consists of a 16-bit unsigned value which contains the actual value to be set, since command 0x59 (envelope control) does only set the type not the actual value (unless most upper bit is set). */ AVSEQ_TRACK_EFFECT_CMD_SET_ENV_VAL = 0x5A, /** NNA (New Note Action) control: Data word consists of two unsigned 8-bit pairs named xx and yy where xx is the kind of note action to be changed and yy the type of note action to be controlled. xx and yy are declared as by the following table: xxyy | Meanings 0x0000 | Note cut (as known to all trackers). 0x0001 | Note off (do a keyoff note on previous note). 0x0002 | Note continue (until sample end). 0x0003 | Note fade (fade out previous note). 0x1100 | Set all DCT (Duplicate Note Check) bits (this is also the same as a xxyy value of 0x11FF). 0x1101 | Set DCT (Duplicate Note Check) Type to instrument note (trigger logical OR combined). 0x1102 | Set DCT to sample note (trigger logical OR combined). 0x1104 | Set DCT to instrument (trigger logical OR combined). 0x1108 | Set DCT to sample (trigger logical OR combined). 0x1110 | Set DCT to instrument note (trigger logical AND combined). 0x1120 | Set DCT to sample note (trigger logical AND combined). 0x1140 | Set DCT to instrument (trigger logical AND combined). 0x1180 | Set DCT to sample (trigger logical AND combined). 0x0100 | Clear all DCT (Duplicate Note Check) bits (this is also the same as a xxyy value of 0x01FF). 0x0101 | Clear DCT to instrument note (logical OR combined). 0x0102 | Clear DCT to sample note (logical OR combined). 0x0104 | Clear DCT to instrument (logical OR combined). 0x0108 | Clear DCT to sample (logical OR combined). 0x0110 | Clear DCT to instrument note (logical AND combined). 0x0120 | Clear DCT to sample note (logical AND combined). 0x0140 | Clear DCT to instrument (logical AND combined). 0x0180 | Clear DCT to sample (logical AND combined). 0x0200 | Set DNA (Duplicate Note Action) to cut duplicate. 0x0201 | Set DNA (Duplicate Note Action) to do a keyoff note. 0x0202 | Set DNA (Duplicate Note Action) to fadeout note. Remember, DCT bits can be combined, e.g. a yy value of 0x06 will affect both instrument and sample note to be logically compared with OR when an xx of 0x11 would be used. */ AVSEQ_TRACK_EFFECT_CMD_NNA_CONTROL = 0x5B, /** Loop control: Data word consists of one upper 4-bit nibble named x and of a 12-bit value named yyy. All values are considered unsigned and the meanings of x change by declarition of the following table which incides the kind of loop control to be applied: x | Meanings 0x0 | Change loop mode where a yyy value of zero means turning off the loop, 0x001 will declare a normal forward loop, 0x002 will declare an always backward loop and 0x003 declares a ping-pong loop (forward <=> backward). 0x1 | Set repeat start value to yyy * 0x100 0x2 | Set repeat length value to yyy * 0x100 0x3 | Set loop counting value or 0x000 for unlimited loop count). 0x4 | Set loop counted value. 0x5 | Change sustain loop mode where a yyy value of zero means turning off the sustain loop, 0x001 will declare a normal forward sustain loop, 0x002 will declare an always backward sustain loop and 0x003 declares a ping pong sustain loop. 0x6 | Set sustain repeat start to yyy * 0x100. 0x7 | Set sustain repeat length to yyy * 0x100. 0x8 | Set sustain loop count value. 0x9 | Set sustain loop counted value. 0xA | Change playback direction where 0xFFF represents backward direction, 0x001 is forward direction and a value of zero indicates a simple inversion of playback direction, */ AVSEQ_TRACK_EFFECT_CMD_SET_LOOP = 0x5C, /* Global effect commands. */ /** Set speed: Data word consists of one upper 4-bit nibble named x and of a 12-bit value named yyy. All values are considered unsigned and the meanings of x indicate what kind of tempo or speed should be changed as declared by the following table: x | Meanings 0 | Change BPM speed (beats per minute) 1 | Change BPM tempo (rows per beat) 2 | Change SPD (MED-style timing) 7 | Apply nominator represented by bits 4-7 of yyy divided by denominator represented in the lower 4 bits of yyy, e.g. a value of 0x025 will scale speed down-rounded by 2/5. If 8 is added is added to x it will only set the value of the but not immediately use it. This can be useful if you want to want to prepare a pattern that uses MED-style SPD timing when the current one uses BPM. If x is 0 or 1, BPM timing will be used. BPM tempo tells how many rows are considered as a beat. The default value for BPM speed is 125, for BPM tempo, 4 and for SPD timing it is 33. To use a pre-defined speed value, just set yyy to zero. x = 7 is a special case, if it's set (default is 1/1), the speed values will be multiplied by the value of the higher nibble of the low word and then divided by the lower nibble of the low word, e.g. a xyyy of 0x7023 will cause SPD timing to be multiplied by 2 and then divided by 3, causing a 2/3 down-rounded of SPD to be used. SPD values smaller or equal than 10 be recognized as old SoundTracker tempos which is required for MED compatibility. */ AVSEQ_TRACK_EFFECT_CMD_SET_SPEED = 0x60, /** Speed slide faster: Data word consists of a 16-bit unsigned value which contains the actual speed faster slide value. It will always slide the currently selected timing mode with set tempo (0x60) command. Note that the new slide faster value will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST = 0x61, /** Speed slide slower: Data word consists of a 16-bit unsigned value which contains the actual speed slower slide value. It will always slide the currently selected timing mode with set tempo (0x60) command. Note that the new slide slower value will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_SLOW = 0x62, /** Fine speed slide faster: Data word consists of a 16-bit unsigned value which contains the actual speed faster slide value. It will always slide the currently selected timing mode with set tempo (0x60) command. Note that the new slide faster value will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). The fine speed slide faster is done only once per row i.e. just executed at the first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST = 0x63, /** Fine speed slide slower: Data word consists of a 16-bit unsigned value which contains the actual speed slower slide value. It will always slide the currently selected timing mode with set tempo (0x60) command. Note that the new slide slower value will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). The fine speed slide slower is done only once per row i.e. just executed at the first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_SLOW = 0x64, /** Speed slide to: Data word consists of two 8-bit pairs named xx and yy where xx represents the unsigned speed ranging from 0x01 - 0xFE to slide to (the target speed desired), 0x00 to execute the slide instead of setting it or 0xFF to execute a fine speed slide instead, i.e. only once per row and yy is the signed slide count number, i.e. the value to be added to current speed. It will always slide the currently selected timing mode with set tempo (0x60) command. Note that the new slide to value will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). */ AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_TO = 0x65, /** Spenolo (vibrato for speed): Data word consists of two 8-bit pairs named xx and yy where xx is the spenolo speed and yy is the spenolo depth. The spenolo values are compatible with the MOD, S3M, XM and IT spenolo if the spenolo envelope with a length of 64 ticks and the amplitude of 256. xx is unsigned and yy is signed. A negative spenolo depth means that the spenolo envelope values will be inverted. It will always apply to the currently selected timing mode with set tempo (0x60) command. Note that the actual tempo will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). */ AVSEQ_TRACK_EFFECT_CMD_SPENOLO = 0x66, /** Spenolo once (vibrato once for speed): Data word consists of two 8-bit pairs named xx and yy where xx is the spenolo speed and yy is the spenolo depth. The spenolo values are compatible with the MOD, S3M, XM and IT spenolo if the spenolo envelope with a length of 64 ticks and the amplitude of 256. The spenolo is done only once per row, i.e. only at first tick. xx is unsigned and yy is signed. A negative spenolo depth means that the spenolo envelope values will be inverted. It will always apply to the currently selected timing mode with set tempo (0x60) command. Note that the actual tempo will only be applied to the playback engine if the selected timing mode is smaller than 8 (see there). */ AVSEQ_TRACK_EFFECT_CMD_SPENOLO_ONCE = 0x67, /** Channel control: Data word consists of one upper 4-bit pair named x, followed by one 4-bit pair named y (bits 8-11) and an 8-bit pair named zz where x is the kind of the channel action and y chooses the channel aspect to be controlled. This effect allows to redirect effects to another channel. The difference between once effects and normal effects are, that once returns after one effect automatically while the other needs a xyzz of 0x0000. This does not affect notes, only effects. The main idea behind this is that channels can control other channels by performing, for example a pattern break. This allows some synchronization within your channels. A MOD, S3M, XM and IT compatible mode can be obtained by using global channel control and a control mode of whole song and affecting non-note effects only, The xy values are declared according to the following table: xy | Meanings 0x00 | Set channel control mode. Exact action is defined by zz as follows: zz | Meanings 0x00 | Disable channel control. 0x01 | Use normal channel control. 0x02 | Use multiple channel control. 0x03 | Use global channel control. 0x04 | Use multiple select channel control. 0x05 | Use multiple deselect channel control. 0x06 | Use multiple invert channel control. 0x10 | Use normal control mode (once control mode). 0x11 | Use one tick control mode. 0x12 | Use one row control mode. 0x13 | Use one track control mode. 0x14 | Use whole song control mode. 0x20 | Affect note effects. 0x21 | Do not affect note effects. 0x30 | Affect non-note effects. 0x31 | Do not affect non-note effects. 0x01 | Set effect channel to zz. 0x02 | Slide effect channel left by zz. 0x03 | Slide effect channel right by zz. 0x04 | Fine slide effect channel left by zz. 0x05 | Fine slide effect channel right by zz. 0x06 | Set target slide effect channel to zz. 0x07 | Do actual slide effect channel to zz. 0x08 | Do actual fine slide effect channel to zz. 0x09 | Channolo (Vibrato for channels). The upper 4 bits of zz are unsigned channolo speed and the lower 4 bits are the the signed channolo depth. A negative channolo depth will cause the channolo envelope values to be inverted. 0x0A | Fine channolo (fine vibrato for channels). The upper 4 bits of zz are unsigned channolo speed and the lower 4 bits are the the signed channolo depth. A negative channolo depth will cause the channolo envelope values to be inverted. The channolo will be executed only once. 0x10 | Channel surround mode. Finer surround control is declared as in the following table: zz | Meanings 0x00 | Turn channel surround panning off. 0x01 | Turn channel surround panning on. 0x10 | Turn track surround panning off. 0x11 | Turn track surround panning on. 0x20 | Turn global surround panning off. 0x21 | Turn global surround panning on. 0x11 | Mutes the channel is zz is zero, un-mutes otherwise. */ AVSEQ_TRACK_EFFECT_CMD_CHANNEL_CTRL = 0x68, /** Set global volume: Data word consists of two 8-bit pairs named xx and yy where xx is the global volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) and yy is the sub-volume global level which allows to set 1/256th of a global volume level. Other volume levels are scaled with global volume. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_G_VOLUME = 0x69, /** Global volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx is the global volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume global slide up level which allows to set 1/256th of a global volume slide up level. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP = 0x6A, /** Global volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the global volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume global slide down level which allows to set 1/256th of a global volume slide down level. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_DOWN = 0x6B, /** Fine global volume slide up: Data word consists of two 8-bit pairs named xx and yy where xx xx is the global volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide up and yy is the sub-volume global slide up level which allows to set 1/256th of a global volume slide up level. The fine global volume slide up is done only once per row, i.e. at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP = 0x6C, /** Fine global volume slide down: Data word consists of two 8-bit pairs named xx and yy where xx is the global volume level (ranging either from 0x00 - 0xFF or in tracker volume mode from 0x00 - 0x40) to slide down and yy is the sub-volume global slide down level which allows to set 1/256th of a global volume slide down level. The fine global volume slide down is done only once per row (at first tick). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_DOWN = 0x6D, /** Global volume slide to: Data word consists of two 8-bit pairs named xx and yy where xx is either the global volume level (ranging either from 0x01 - 0xFE or in tracker volume mode from 0x01 - 0x3F) to slide to (the target global volume desired) and yy is the sub-volume global slide to level which allows to set 1/256th of a global volume slide to level, 0x00 to execute the slide instead of setting it or 0xFF to execute a fine global volume slide instead (only once per row). Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_TO = 0x6E, /** Global tremolo: Data word consists of two 8-bit pairs named xx and yy where xx is the global tremolo speed and yy is the global tremolo depth. The global tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. xx is unsigned and yy is signed. A negative global tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_G_TREMOLO = 0x6F, /** Global tremolo once: Data word consists of two 8-bit pairs named xx and yy where xx is the global tremolo speed and yy is the global tremolo depth. The global tremolo values are compatible with the MOD, S3M, XM and IT tremolo if an inverted tremolo envelope with a length of 64 ticks and the amplitude of 256 is used. The tremolo is executed only once per row, i.e. at first tick. xx is unsigned and yy is signed. A negative tremolo depth means that the tremolo envelope values will be inverted. */ AVSEQ_TRACK_EFFECT_CMD_G_TREMO_ONCE = 0x70, /** Set global panning: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning position ranging from 0x00 (full stereo left panning) to 0xFF (full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) and yy is the sub-panning position which allows to set 1/256th of a global panning position. Other stereo positions are scaled to global panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_SET_G_PAN = 0x71, /** Global panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning left slide position ranging from 0x00 - 0xFF and yy is the sub-panning global slide left position which allows to set 1/256th of a panning slide left position. Other stereo positions are scaled to global panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT = 0x72, /** Global panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning global slide right position which allows to set 1/256th of a panning slide right position. Other stereo positions are scaled to global panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_GPANSL_RIGHT = 0x73, /** Fine global panning slide left: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning left slide position ranging from 0x00 - 0xFF and yy is the sub-panning global slide left position which allows to set 1/256th of a panning slide left position. Other stereo positions are scaled to global panning position. The fine global panning slide left is done only once per row, i.e. only at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT = 0x74, /** Fine global panning slide right: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning right slide position ranging from 0x00 - 0xFF and yy is the sub-panning global slide right position which allows to set 1/256th of a panning slide right position. Other stereo positions are scaled to global panning position. The fine global panning slide right is done only once per row, i.e. only at first tick. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_FGP_SL_RIGHT = 0x75, /** Global panning slide to: Data word consists of two 8-bit pairs named xx and yy where xx is the global panning position ranging from 0x01 (almost full stereo left panning) to 0xFE (almost full stereo right panning) while 0x80 is exact centered panning (i.e. the note will be played with half of volume at left and right speakers) to slide to (the target global stereo position desired) and yy is the sub-panning global slide to position which allows to set 1/256th of a global panning slide to position, 0x00 to execute the slide instead of setting it or 0xFF to do a fine global panning slide instead, i.e. execute it only once per row (at first tick). Other stereo positions are scaled to global panning position. Both xx and yy are unsigned values. */ AVSEQ_TRACK_EFFECT_CMD_GPANSL_TO = 0x76, /** Global pannolo / panbrello: Data word consists of two 8-bit pairs named xx and yy where xx is the global pannolo speed and yy is the global pannolo depth. The global pannolo values are compatible with the MOD, S3M, XM and IT pannolo if an inverted pannolo envelope with
BastyCDGS/ffmpeg-soc
92d26f8a564657ccde0fd8dde9631804d645d3e9
Fixed some typo in note frequency lookup table in AVSequencer player.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 425d6bf..3aebfc2 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -962,1025 +962,1025 @@ static void play_key_off(AVSequencerPlayerChannel *const player_channel) if ((sample->flags & AVSEQ_SAMPLE_FLAG_LOOP) && repeat_length) { flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (sample->repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (sample->repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = flags; } if ((waveform = player_channel->sample_waveform) && (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_SUSTAIN_LOOP)) { repeat = waveform->repeat; repeat_length = waveform->rep_len; repeat_count = waveform->rep_count; player_channel->mixer.repeat_start = repeat; player_channel->mixer.repeat_length = repeat_length; player_channel->mixer.repeat_count = repeat_count; flags = player_channel->mixer.flags & ~(AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG|AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS); if (!(waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_NOLOOP) && repeat_length) { flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (waveform->repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_PINGPONG) flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (waveform->repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_BACKWARDS) flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = flags; } if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME) player_channel->entry_pos[0] = player_channel->sustain_pos[0]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING) player_channel->entry_pos[1] = player_channel->sustain_pos[1]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE) player_channel->entry_pos[2] = player_channel->sustain_pos[2]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL) player_channel->entry_pos[3] = player_channel->sustain_pos[3]; } /** Linear frequency table. Value is 16777216*2^(x/3072). */ static const uint32_t linear_frequency_lut[] = { 16777216, 16781002, 16784789, 16788576, 16792365, 16796154, 16799944, 16803735, 16807527, 16811320, 16815114, 16818908, 16822704, 16826500, 16830297, 16834095, 16837894, 16841693, 16845494, 16849295, 16853097, 16856900, 16860704, 16864509, 16868315, 16872121, 16875928, 16879737, 16883546, 16887356, 16891166, 16894978, 16898791, 16902604, 16906418, 16910233, 16914049, 16917866, 16921684, 16925502, 16929322, 16933142, 16936963, 16940785, 16944608, 16948432, 16952256, 16956082, 16959908, 16963735, 16967563, 16971392, 16975222, 16979052, 16982884, 16986716, 16990549, 16994383, 16998218, 17002054, 17005891, 17009728, 17013567, 17017406, 17021246, 17025087, 17028929, 17032772, 17036615, 17040460, 17044305, 17048151, 17051999, 17055846, 17059695, 17063545, 17067396, 17071247, 17075099, 17078952, 17082806, 17086661, 17090517, 17094374, 17098231, 17102090, 17105949, 17109809, 17113670, 17117532, 17121394, 17125258, 17129123, 17132988, 17136854, 17140721, 17144589, 17148458, 17152328, 17156198, 17160070, 17163942, 17167815, 17171689, 17175564, 17179440, 17183317, 17187194, 17191073, 17194952, 17198832, 17202713, 17206595, 17210478, 17214362, 17218247, 17222132, 17226018, 17229906, 17233794, 17237683, 17241572, 17245463, 17249355, 17253247, 17257141, 17261035, 17264930, 17268826, 17272723, 17276621, 17280519, 17284419, 17288319, 17292220, 17296123, 17300026, 17303929, 17307834, 17311740, 17315646, 17319554, 17323462, 17327371, 17331282, 17335192, 17339104, 17343017, 17346931, 17350845, 17354761, 17358677, 17362594, 17366512, 17370431, 17374351, 17378271, 17382193, 17386115, 17390039, 17393963, 17397888, 17401814, 17405741, 17409669, 17413597, 17417527, 17421457, 17425389, 17429321, 17433254, 17437188, 17441123, 17445059, 17448995, 17452933, 17456871, 17460810, 17464751, 17468692, 17472634, 17476577, 17480520, 17484465, 17488410, 17492357, 17496304, 17500252, 17504202, 17508152, 17512102, 17516054, 17520007, 17523960, 17527915, 17531870, 17535826, 17539783, 17543742, 17547700, 17551660, 17555621, 17559583, 17563545, 17567508, 17571473, 17575438, 17579404, 17583371, 17587339, 17591307, 17595277, 17599248, 17603219, 17607191, 17611165, 17615139, 17619114, 17623090, 17627066, 17631044, 17635023, 17639002, 17642983, 17646964, 17650946, 17654929, 17658913, 17662898, 17666884, 17670871, 17674858, 17678847, 17682836, 17686826, 17690818, 17694810, 17698803, 17702797, 17706791, 17710787, 17714784, 17718781, 17722780, 17726779, 17730779, 17734780, 17738782, 17742785, 17746789, 17750794, 17754799, 17758806, 17762813, 17766822, 17770831, 17774841, 17778852, 17782864, 17786877, 17790891, 17794906, 17798921, 17802938, 17806955, 17810973, 17814993, 17819013, 17823034, 17827056, 17831078, 17835102, 17839127, 17843152, 17847179, 17851206, 17855235, 17859264, 17863294, 17867325, 17871357, 17875390, 17879423, 17883458, 17887494, 17891530, 17895567, 17899606, 17903645, 17907685, 17911726, 17915768, 17919811, 17923855, 17927899, 17931945, 17935992, 17940039, 17944087, 17948137, 17952187, 17956238, 17960290, 17964343, 17968397, 17972451, 17976507, 17980563, 17984621, 17988679, 17992739, 17996799, 18000860, 18004922, 18008985, 18013049, 18017114, 18021180, 18025246, 18029314, 18033382, 18037452, 18041522, 18045593, 18049665, 18053738, 18057812, 18061887, 18065963, 18070040, 18074118, 18078196, 18082276, 18086356, 18090437, 18094520, 18098603, 18102687, 18106772, 18110858, 18114945, 18119033, 18123121, 18127211, 18131302, 18135393, 18139486, 18143579, 18147673, 18151768, 18155865, 18159962, 18164060, 18168158, 18172258, 18176359, 18180461, 18184563, 18188667, 18192771, 18196877, 18200983, 18205090, 18209198, 18213307, 18217417, 18221528, 18225640, 18229753, 18233867, 18237981, 18242097, 18246213, 18250331, 18254449, 18258568, 18262689, 18266810, 18270932, 18275055, 18279179, 18283304, 18287429, 18291556, 18295684, 18299812, 18303942, 18308072, 18312204, 18316336, 18320469, 18324603, 18328739, 18332875, 18337012, 18341150, 18345288, 18349428, 18353569, 18357711, 18361853, 18365997, 18370141, 18374287, 18378433, 18382580, 18386728, 18390877, 18395028, 18399179, 18403330, 18407483, 18411637, 18415792, 18419948, 18424104, 18428262, 18432420, 18436580, 18440740, 18444902, 18449064, 18453227, 18457391, 18461556, 18465722, 18469889, 18474057, 18478226, 18482396, 18486566, 18490738, 18494911, 18499084, 18503259, 18507434, 18511611, 18515788, 18519966, 18524145, 18528325, 18532507, 18536689, 18540872, 18545056, 18549240, 18553426, 18557613, 18561801, 18565989, 18570179, 18574369, 18578561, 18582753, 18586947, 18591141, 18595336, 18599532, 18603730, 18607928, 18612127, 18616327, 18620528, 18624730, 18628932, 18633136, 18637341, 18641547, 18645753, 18649961, 18654169, 18658379, 18662589, 18666801, 18671013, 18675226, 18679441, 18683656, 18687872, 18692089, 18696307, 18700526, 18704746, 18708967, 18713189, 18717412, 18721635, 18725860, 18730086, 18734312, 18738540, 18742768, 18746998, 18751228, 18755460, 18759692, 18763925, 18768160, 18772395, 18776631, 18780868, 18785106, 18789345, 18793585, 18797826, 18802068, 18806311, 18810555, 18814800, 18819045, 18823292, 18827540, 18831788, 18836038, 18840288, 18844540, 18848792, 18853046, 18857300, 18861555, 18865812, 18870069, 18874327, 18878586, 18882846, 18887107, 18891370, 18895633, 18899897, 18904161, 18908427, 18912694, 18916962, 18921231, 18925501, 18929771, 18934043, 18938316, 18942589, 18946864, 18951139, 18955416, 18959693, 18963972, 18968251, 18972531, 18976813, 18981095, 18985378, 18989663, 18993948, 18998234, 19002521, 19006809, 19011098, 19015388, 19019679, 19023971, 19028264, 19032558, 19036853, 19041149, 19045446, 19049743, 19054042, 19058342, 19062643, 19066944, 19071247, 19075550, 19079855, 19084161, 19088467, 19092775, 19097083, 19101392, 19105703, 19110014, 19114327, 19118640, 19122954, 19127270, 19131586, 19135903, 19140221, 19144540, 19148861, 19153182, 19157504, 19161827, 19166151, 19170476, 19174802, 19179129, 19183457, 19187786, 19192116, 19196446, 19200778, 19205111, 19209445, 19213780, 19218116, 19222452, 19226790, 19231129, 19235468, 19239809, 19244151, 19248493, 19252837, 19257182, 19261527, 19265874, 19270221, 19274570, 19278919, 19283270, 19287621, 19291973, 19296327, 19300681, 19305037, 19309393, 19313750, 19318109, 19322468, 19326828, 19331190, 19335552, 19339915, 19344279, 19348645, 19353011, 19357378, 19361746, 19366115, 19370485, 19374857, 19379229, 19383602, 19387976, 19392351, 19396727, 19401104, 19405482, 19409861, 19414241, 19418622, 19423004, 19427387, 19431771, 19436156, 19440542, 19444929, 19449317, 19453706, 19458096, 19462487, 19466878, 19471271, 19475665, 19480060, 19484456, 19488853, 19493251, 19497649, 19502049, 19506450, 19510852, 19515255, 19519659, 19524063, 19528469, 19532876, 19537284, 19541692, 19546102, 19550513, 19554925, 19559337, 19563751, 19568166, 19572582, 19576998, 19581416, 19585835, 19590255, 19594675, 19599097, 19603520, 19607943, 19612368, 19616794, 19621221, 19625648, 19630077, 19634507, 19638937, 19643369, 19647802, 19652236, 19656670, 19661106, 19665543, 19669980, 19674419, 19678859, 19683300, 19687741, 19692184, 19696628, 19701072, 19705518, 19709965, 19714413, 19718861, 19723311, 19727762, 19732214, 19736666, 19741120, 19745575, 19750031, 19754488, 19758945, 19763404, 19767864, 19772325, 19776786, 19781249, 19785713, 19790178, 19794644, 19799111, 19803578, 19808047, 19812517, 19816988, 19821460, 19825933, 19830407, 19834882, 19839358, 19843835, 19848313, 19852791, 19857271, 19861752, 19866234, 19870717, 19875201, 19879686, 19884172, 19888660, 19893148, 19897637, 19902127, 19906618, 19911110, 19915603, 19920097, 19924592, 19929089, 19933586, 19938084, 19942583, 19947083, 19951585, 19956087, 19960590, 19965094, 19969600, 19974106, 19978613, 19983122, 19987631, 19992142, 19996653, 20001165, 20005679, 20010193, 20014709, 20019225, 20023743, 20028261, 20032781, 20037302, 20041823, 20046346, 20050869, 20055394, 20059920, 20064446, 20068974, 20073503, 20078033, 20082564, 20087095, 20091628, 20096162, 20100697, 20105233, 20109770, 20114308, 20118847, 20123387, 20127928, 20132470, 20137013, 20141557, 20146102, 20150648, 20155195, 20159744, 20164293, 20168843, 20173394, 20177947, 20182500, 20187054, 20191610, 20196166, 20200724, 20205282, 20209842, 20214402, 20218964, 20223526, 20228090, 20232655, 20237220, 20241787, 20246355, 20250924, 20255493, 20260064, 20264636, 20269209, 20273783, 20278358, 20282934, 20287511, 20292089, 20296668, 20301248, 20305829, 20310412, 20314995, 20319579, 20324164, 20328751, 20333338, 20337927, 20342516, 20347107, 20351698, 20356291, 20360884, 20365479, 20370074, 20374671, 20379269, 20383868, 20388467, 20393068, 20397670, 20402273, 20406877, 20411482, 20416088, 20420695, 20425303, 20429912, 20434523, 20439134, 20443746, 20448360, 20452974, 20457589, 20462206, 20466823, 20471442, 20476061, 20480682, 20485304, 20489926, 20494550, 20499175, 20503801, 20508428, 20513055, 20517684, 20522314, 20526945, 20531578, 20536211, 20540845, 20545480, 20550116, 20554754, 20559392, 20564032, 20568672, 20573313, 20577956, 20582600, 20587244, 20591890, 20596537, 20601185, 20605833, 20610483, 20615134, 20619786, 20624439, 20629093, 20633749, 20638405, 20643062, 20647720, 20652380, 20657040, 20661701, 20666364, 20671028, 20675692, 20680358, 20685025, 20689692, 20694361, 20699031, 20703702, 20708374, 20713047, 20717721, 20722396, 20727072, 20731750, 20736428, 20741107, 20745788, 20750469, 20755152, 20759835, 20764520, 20769206, 20773892, 20778580, 20783269, 20787959, 20792650, 20797342, 20802035, 20806729, 20811425, 20816121, 20820818, 20825517, 20830216, 20834917, 20839618, 20844321, 20849025, 20853729, 20858435, 20863142, 20867850, 20872559, 20877269, 20881980, 20886693, 20891406, 20896120, 20900836, 20905552, 20910270, 20914988, 20919708, 20924429, 20929150, 20933873, 20938597, 20943322, 20948048, 20952775, 20957504, 20962233, 20966963, 20971695, 20976427, 20981161, 20985895, 20990631, 20995368, 21000105, 21004844, 21009584, 21014325, 21019067, 21023810, 21028555, 21033300, 21038046, 21042794, 21047542, 21052292, 21057042, 21061794, 21066547, 21071301, 21076056, 21080812, 21085569, 21090327, 21095086, 21099846, 21104608, 21109370, 21114134, 21118898, 21123664, 21128431, 21133199, 21137968, 21142738, 21147509, 21152281, 21157054, 21161828, 21166604, 21171380, 21176158, 21180936, 21185716, 21190497, 21195278, 21200061, 21204845, 21209630, 21214417, 21219204, 21223992, 21228781, 21233572, 21238364, 21243156, 21247950, 21252745, 21257541, 21262338, 21267136, 21271935, 21276735, 21281536, 21286339, 21291142, 21295947, 21300752, 21305559, 21310367, 21315176, 21319986, 21324797, 21329609, 21334422, 21339236, 21344052, 21348868, 21353686, 21358504, 21363324, 21368145, 21372967, 21377790, 21382614, 21387439, 21392265, 21397093, 21401921, 21406751, 21411581, 21416413, 21421246, 21426080, 21430915, 21435751, 21440588, 21445426, 21450266, 21455106, 21459948, 21464790, 21469634, 21474479, 21479325, 21484172, 21489020, 21493869, 21498719, 21503571, 21508423, 21513277, 21518132, 21522987, 21527844, 21532702, 21537561, 21542421, 21547283, 21552145, 21557008, 21561873, 21566739, 21571605, 21576473, 21581342, 21586212, 21591083, 21595955, 21600829, 21605703, 21610579, 21615455, 21620333, 21625212, 21630092, 21634973, 21639855, 21644738, 21649623, 21654508, 21659395, 21664282, 21669171, 21674061, 21678952, 21683844, 21688737, 21693631, 21698527, 21703423, 21708321, 21713219, 21718119, 21723020, 21727922, 21732825, 21737729, 21742635, 21747541, 21752449, 21757357, 21762267, 21767178, 21772090, 21777003, 21781917, 21786832, 21791749, 21796666, 21801585, 21806505, 21811426, 21816348, 21821271, 21826195, 21831120, 21836046, 21840974, 21845903, 21850832, 21855763, 21860695, 21865628, 21870562, 21875498, 21880434, 21885372, 21890310, 21895250, 21900191, 21905133, 21910076, 21915020, 21919965, 21924912, 21929859, 21934808, 21939758, 21944709, 21949661, 21954614, 21959568, 21964524, 21969480, 21974438, 21979396, 21984356, 21989317, 21994279, 21999243, 22004207, 22009172, 22014139, 22019107, 22024076, 22029045, 22034016, 22038989, 22043962, 22048936, 22053912, 22058889, 22063866, 22068845, 22073825, 22078807, 22083789, 22088772, 22093757, 22098742, 22103729, 22108717, 22113706, 22118696, 22123688, 22128680, 22133674, 22138668, 22143664, 22148661, 22153659, 22158658, 22163659, 22168660, 22173663, 22178666, 22183671, 22188677, 22193684, 22198692, 22203702, 22208712, 22213724, 22218736, 22223750, 22228765, 22233781, 22238799, 22243817, 22248837, 22253857, 22258879, 22263902, 22268926, 22273951, 22278978, 22284005, 22289034, 22294063, 22299094, 22304126, 22309159, 22314194, 22319229, 22324266, 22329303, 22334342, 22339382, 22344423, 22349465, 22354509, 22359553, 22364599, 22369646, 22374693, 22379743, 22384793, 22389844, 22394897, 22399950, 22405005, 22410061, 22415118, 22420176, 22425235, 22430296, 22435357, 22440420, 22445484, 22450549, 22455615, 22460683, 22465751, 22470821, 22475891, 22480963, 22486036, 22491111, 22496186, 22501262, 22506340, 22511419, 22516499, 22521580, 22526662, 22531745, 22536830, 22541915, 22547002, 22552090, 22557179, 22562269, 22567361, 22572453, 22577547, 22582642, 22587738, 22592835, 22597933, 22603033, 22608133, 22613235, 22618338, 22623442, 22628547, 22633653, 22638761, 22643870, 22648979, 22654090, 22659202, 22664316, 22669430, 22674546, 22679662, 22684780, 22689899, 22695020, 22700141, 22705263, 22710387, 22715512, 22720638, 22725765, 22730893, 22736023, 22741153, 22746285, 22751418, 22756552, 22761687, 22766824, 22771961, 22777100, 22782240, 22787381, 22792523, 22797666, 22802811, 22807956, 22813103, 22818251, 22823400, 22828551, 22833702, 22838855, 22844009, 22849164, 22854320, 22859477, 22864635, 22869795, 22874956, 22880118, 22885281, 22890445, 22895611, 22900777, 22905945, 22911114, 22916284, 22921455, 22926628, 22931801, 22936976, 22942152, 22947329, 22952508, 22957687, 22962868, 22968049, 22973232, 22978416, 22983602, 22988788, 22993976, 22999165, 23004355, 23009546, 23014738, 23019932, 23025126, 23030322, 23035519, 23040717, 23045917, 23051117, 23056319, 23061522, 23066726, 23071931, 23077137, 23082345, 23087554, 23092764, 23097975, 23103187, 23108400, 23113615, 23118831, 23124048, 23129266, 23134485, 23139706, 23144928, 23150150, 23155374, 23160600, 23165826, 23171054, 23176282, 23181512, 23186743, 23191976, 23197209, 23202444, 23207680, 23212917, 23218155, 23223394, 23228635, 23233877, 23239120, 23244364, 23249609, 23254856, 23260103, 23265352, 23270602, 23275853, 23281106, 23286359, 23291614, 23296870, 23302127, 23307386, 23312645, 23317906, 23323168, 23328431, 23333695, 23338961, 23344227, 23349495, 23354764, 23360034, 23365306, 23370578, 23375852, 23381127, 23386403, 23391681, 23396959, 23402239, 23407520, 23412802, 23418085, 23423370, 23428656, 23433942, 23439231, 23444520, 23449810, 23455102, 23460395, 23465689, 23470984, 23476281, 23481578, 23486877, 23492177, 23497478, 23502781, 23508084, 23513389, 23518695, 23524002, 23529311, 23534620, 23539931, 23545243, 23550556, 23555871, 23561186, 23566503, 23571821, 23577140, 23582461, 23587782, 23593105, 23598429, 23603754, 23609081, 23614408, 23619737, 23625067, 23630399, 23635731, 23641065, 23646399, 23651735, 23657073, 23662411, 23667751, 23673092, 23678434, 23683777, 23689121, 23694467, 23699814, 23705162, 23710511, 23715862, 23721213, 23726566, 23731921, 23737276, 23742632, 23747990, 23753349, 23758709, 23764071, 23769433, 23774797, 23780162, 23785528, 23790896, 23796264, 23801634, 23807005, 23812377, 23817751, 23823126, 23828502, 23833879, 23839257, 23844637, 23850017, 23855399, 23860783, 23866167, 23871553, 23876939, 23882327, 23887717, 23893107, 23898499, 23903892, 23909286, 23914681, 23920078, 23925476, 23930875, 23936275, 23941676, 23947079, 23952483, 23957888, 23963294, 23968702, 23974111, 23979521, 23984932, 23990344, 23995758, 24001173, 24006589, 24012006, 24017425, 24022844, 24028265, 24033688, 24039111, 24044536, 24049962, 24055389, 24060817, 24066246, 24071677, 24077109, 24082542, 24087977, 24093413, 24098850, 24104288, 24109727, 24115168, 24120609, 24126052, 24131497, 24136942, 24142389, 24147837, 24153286, 24158736, 24164188, 24169641, 24175095, 24180550, 24186007, 24191465, 24196924, 24202384, 24207846, 24213308, 24218772, 24224237, 24229704, 24235172, 24240640, 24246111, 24251582, 24257055, 24262528, 24268003, 24273480, 24278957, 24284436, 24289916, 24295397, 24300880, 24306363, 24311848, 24317335, 24322822, 24328311, 24333801, 24339292, 24344784, 24350278, 24355773, 24361269, 24366766, 24372265, 24377765, 24383266, 24388768, 24394271, 24399776, 24405282, 24410790, 24416298, 24421808, 24427319, 24432831, 24438345, 24443859, 24449375, 24454893, 24460411, 24465931, 24471452, 24476974, 24482497, 24488022, 24493548, 24499075, 24504604, 24510133, 24515664, 24521197, 24526730, 24532265, 24537801, 24543338, 24548876, 24554416, 24559957, 24565499, 24571042, 24576587, 24582133, 24587680, 24593229, 24598778, 24604329, 24609881, 24615435, 24620990, 24626546, 24632103, 24637661, 24643221, 24648782, 24654344, 24659908, 24665472, 24671038, 24676606, 24682174, 24687744, 24693315, 24698887, 24704461, 24710036, 24715612, 24721189, 24726767, 24732347, 24737928, 24743511, 24749094, 24754679, 24760265, 24765853, 24771441, 24777031, 24782622, 24788215, 24793809, 24799403, 24805000, 24810597, 24816196, 24821796, 24827397, 24833000, 24838604, 24844209, 24849815, 24855423, 24861031, 24866641, 24872253, 24877866, 24883479, 24889095, 24894711, 24900329, 24905948, 24911568, 24917190, 24922812, 24928436, 24934062, 24939688, 24945316, 24950945, 24956576, 24962208, 24967840, 24973475, 24979110, 24984747, 24990385, 24996024, 25001665, 25007307, 25012950, 25018594, 25024240, 25029887, 25035535, 25041185, 25046835, 25052487, 25058141, 25063795, 25069451, 25075108, 25080767, 25086427, 25092088, 25097750, 25103413, 25109078, 25114744, 25120412, 25126080, 25131750, 25137421, 25143094, 25148768, 25154443, 25160119, 25165797, 25171476, 25177156, 25182837, 25188520, 25194204, 25199889, 25205576, 25211264, 25216953, 25222643, 25228335, 25234028, 25239722, 25245418, 25251115, 25256813, 25262512, 25268213, 25273915, 25279618, 25285323, 25291029, 25296736, 25302445, 25308154, 25313865, 25319578, 25325291, 25331006, 25336722, 25342440, 25348158, 25353879, 25359600, 25365322, 25371046, 25376772, 25382498, 25388226, 25393955, 25399685, 25405417, 25411150, 25416884, 25422620, 25428357, 25434095, 25439834, 25445575, 25451317, 25457060, 25462805, 25468551, 25474298, 25480047, 25485796, 25491548, 25497300, 25503054, 25508809, 25514565, 25520323, 25526081, 25531842, 25537603, 25543366, 25549130, 25554895, 25560662, 25566430, 25572199, 25577970, 25583742, 25589515, 25595290, 25601066, 25606843, 25612621, 25618401, 25624182, 25629964, 25635748, 25641533, 25647319, 25653107, 25658895, 25664686, 25670477, 25676270, 25682064, 25687859, 25693656, 25699454, 25705253, 25711054, 25716856, 25722659, 25728464, 25734270, 25740077, 25745885, 25751695, 25757506, 25763319, 25769132, 25774947, 25780764, 25786581, 25792400, 25798221, 25804042, 25809865, 25815689, 25821515, 25827342, 25833170, 25839000, 25844830, 25850662, 25856496, 25862331, 25868167, 25874004, 25879843, 25885683, 25891524, 25897367, 25903211, 25909056, 25914903, 25920751, 25926600, 25932451, 25938302, 25944156, 25950010, 25955866, 25961723, 25967582, 25973442, 25979303, 25985165, 25991029, 25996894, 26002761, 26008628, 26014497, 26020368, 26026240, 26032113, 26037987, 26043863, 26049740, 26055618, 26061498, 26067379, 26073261, 26079145, 26085030, 26090916, 26096804, 26102693, 26108583, 26114475, 26120368, 26126262, 26132158, 26138055, 26143953, 26149853, 26155754, 26161656, 26167559, 26173464, 26179371, 26185278, 26191187, 26197098, 26203009, 26208922, 26214836, 26220752, 26226669, 26232587, 26238507, 26244428, 26250350, 26256274, 26262199, 26268125, 26274053, 26279982, 26285912, 26291844, 26297777, 26303711, 26309647, 26315584, 26321522, 26327462, 26333403, 26339345, 26345289, 26351234, 26357180, 26363128, 26369077, 26375028, 26380979, 26386933, 26392887, 26398843, 26404800, 26410758, 26416718, 26422679, 26428642, 26434606, 26440571, 26446538, 26452506, 26458475, 26464445, 26470417, 26476391, 26482365, 26488341, 26494319, 26500297, 26506277, 26512259, 26518241, 26524226, 26530211, 26536198, 26542186, 26548175, 26554166, 26560158, 26566152, 26572147, 26578143, 26584141, 26590140, 26596140, 26602142, 26608145, 26614149, 26620155, 26626162, 26632170, 26638180, 26644191, 26650204, 26656218, 26662233, 26668249, 26674267, 26680287, 26686307, 26692329, 26698353, 26704377, 26710404, 26716431, 26722460, 26728490, 26734522, 26740554, 26746589, 26752624, 26758661, 26764700, 26770739, 26776780, 26782823, 26788867, 26794912, 26800958, 26807006, 26813055, 26819106, 26825158, 26831211, 26837266, 26843322, 26849380, 26855438, 26861499, 26867560, 26873623, 26879687, 26885753, 26891820, 26897888, 26903958, 26910029, 26916102, 26922176, 26928251, 26934327, 26940405, 26946485, 26952566, 26958648, 26964731, 26970816, 26976902, 26982990, 26989079, 26995169, 27001261, 27007354, 27013448, 27019544, 27025641, 27031740, 27037840, 27043941, 27050044, 27056148, 27062254, 27068360, 27074469, 27080578, 27086689, 27092802, 27098915, 27105030, 27111147, 27117265, 27123384, 27129505, 27135627, 27141750, 27147875, 27154001, 27160129, 27166258, 27172388, 27178520, 27184653, 27190787, 27196923, 27203060, 27209199, 27215339, 27221480, 27227623, 27233767, 27239913, 27246060, 27252208, 27258358, 27264509, 27270661, 27276815, 27282971, 27289127, 27295285, 27301445, 27307605, 27313768, 27319931, 27326096, 27332263, 27338430, 27344600, 27350770, 27356942, 27363116, 27369290, 27375466, 27381644, 27387823, 27394003, 27400185, 27406368, 27412552, 27418738, 27424926, 27431114, 27437304, 27443496, 27449689, 27455883, 27462079, 27468276, 27474474, 27480674, 27486875, 27493078, 27499282, 27505488, 27511695, 27517903, 27524112, 27530324, 27536536, 27542750, 27548965, 27555182, 27561400, 27567619, 27573840, 27580063, 27586286, 27592511, 27598738, 27604966, 27611195, 27617426, 27623658, 27629892, 27636126, 27642363, 27648601, 27654840, 27661080, 27667322, 27673566, 27679810, 27686057, 27692304, 27698553, 27704804, 27711056, 27717309, 27723564, 27729820, 27736077, 27742336, 27748596, 27754858, 27761121, 27767386, 27773652, 27779919, 27786188, 27792458, 27798730, 27805003, 27811277, 27817553, 27823830, 27830109, 27836389, 27842671, 27848954, 27855238, 27861524, 27867811, 27874100, 27880390, 27886681, 27892974, 27899268, 27905564, 27911861, 27918160, 27924460, 27930761, 27937064, 27943368, 27949674, 27955981, 27962290, 27968600, 27974911, 27981224, 27987538, 27993854, 28000171, 28006489, 28012809, 28019131, 28025453, 28031778, 28038103, 28044430, 28050759, 28057089, 28063420, 28069753, 28076087, 28082423, 28088760, 28095098, 28101438, 28107779, 28114122, 28120466, 28126812, 28133159, 28139508, 28145858, 28152209, 28158562, 28164916, 28171272, 28177629, 28183987, 28190347, 28196709, 28203072, 28209436, 28215802, 28222169, 28228537, 28234907, 28241279, 28247652, 28254026, 28260402, 28266779, 28273158, 28279538, 28285919, 28292302, 28298687, 28305073, 28311460, 28317849, 28324239, 28330631, 28337024, 28343418, 28349814, 28356211, 28362610, 28369011, 28375412, 28381816, 28388220, 28394626, 28401034, 28407443, 28413853, 28420265, 28426678, 28433093, 28439509, 28445927, 28452346, 28458766, 28465188, 28471612, 28478037, 28484463, 28490891, 28497320, 28503751, 28510183, 28516616, 28523052, 28529488, 28535926, 28542365, 28548806, 28555249, 28561692, 28568137, 28574584, 28581032, 28587482, 28593933, 28600385, 28606839, 28613295, 28619752, 28626210, 28632670, 28639131, 28645594, 28652058, 28658523, 28664990, 28671459, 28677929, 28684400, 28690873, 28697348, 28703823, 28710301, 28716779, 28723260, 28729741, 28736224, 28742709, 28749195, 28755683, 28762172, 28768662, 28775154, 28781647, 28788142, 28794639, 28801136, 28807636, 28814136, 28820638, 28827142, 28833647, 28840154, 28846662, 28853171, 28859682, 28866195, 28872709, 28879224, 28885741, 28892259, 28898779, 28905300, 28911823, 28918347, 28924873, 28931400, 28937929, 28944459, 28950991, 28957524, 28964058, 28970594, 28977132, 28983671, 28990211, 28996753, 29003296, 29009841, 29016388, 29022935, 29029485, 29036035, 29042588, 29049141, 29055697, 29062253, 29068811, 29075371, 29081932, 29088495, 29095059, 29101625, 29108192, 29114760, 29121330, 29127902, 29134475, 29141049, 29147625, 29154202, 29160781, 29167362, 29173944, 29180527, 29187112, 29193698, 29200286, 29206875, 29213466, 29220058, 29226652, 29233248, 29239844, 29246443, 29253042, 29259643, 29266246, 29272850, 29279456, 29286063, 29292672, 29299282, 29305894, 29312507, 29319122, 29325738, 29332355, 29338974, 29345595, 29352217, 29358841, 29365466, 29372092, 29378720, 29385350, 29391981, 29398614, 29405248, 29411883, 29418520, 29425159, 29431799, 29438441, 29445084, 29451728, 29458374, 29465022, 29471671, 29478321, 29484974, 29491627, 29498282, 29504939, 29511597, 29518256, 29524917, 29531580, 29538244, 29544910, 29551577, 29558245, 29564915, 29571587, 29578260, 29584935, 29591611, 29598288, 29604968, 29611648, 29618330, 29625014, 29631699, 29638386, 29645074, 29651764, 29658455, 29665148, 29671842, 29678538, 29685235, 29691934, 29698634, 29705336, 29712039, 29718744, 29725450, 29732158, 29738867, 29745578, 29752290, 29759004, 29765720, 29772437, 29779155, 29785875, 29792596, 29799319, 29806044, 29812770, 29819497, 29826226, 29832957, 29839689, 29846423, 29853158, 29859894, 29866633, 29873372, 29880113, 29886856, 29893600, 29900346, 29907094, 29913842, 29920593, 29927345, 29934098, 29940853, 29947609, 29954367, 29961127, 29967888, 29974650, 29981414, 29988180, 29994947, 30001716, 30008486, 30015257, 30022031, 30028805, 30035582, 30042360, 30049139, 30055920, 30062702, 30069486, 30076272, 30083059, 30089847, 30096637, 30103429, 30110222, 30117016, 30123813, 30130610, 30137410, 30144210, 30151013, 30157817, 30164622, 30171429, 30178237, 30185047, 30191859, 30198672, 30205487, 30212303, 30219120, 30225940, 30232760, 30239583, 30246407, 30253232, 30260059, 30266887, 30273717, 30280549, 30287382, 30294217, 30301053, 30307890, 30314730, 30321571, 30328413, 30335257, 30342102, 30348949, 30355798, 30362648, 30369499, 30376353, 30383207, 30390064, 30396921, 30403781, 30410642, 30417504, 30424368, 30431234, 30438101, 30444969, 30451839, 30458711, 30465584, 30472459, 30479336, 30486214, 30493093, 30499974, 30506857, 30513741, 30520627, 30527514, 30534403, 30541293, 30548185, 30555079, 30561974, 30568870, 30575768, 30582668, 30589569, 30596472, 30603377, 30610282, 30617190, 30624099, 30631010, 30637922, 30644836, 30651751, 30658668, 30665586, 30672506, 30679428, 30686351, 30693275, 30700202, 30707129, 30714059, 30720990, 30727922, 30734856, 30741792, 30748729, 30755668, 30762608, 30769550, 30776493, 30783438, 30790385, 30797333, 30804283, 30811234, 30818187, 30825141, 30832097, 30839055, 30846014, 30852975, 30859937, 30866901, 30873866, 30880833, 30887802, 30894772, 30901743, 30908717, 30915691, 30922668, 30929646, 30936625, 30943607, 30950589, 30957574, 30964559, 30971547, 30978536, 30985526, 30992519, 30999512, 31006508, 31013505, 31020503, 31027503, 31034505, 31041508, 31048513, 31055519, 31062527, 31069537, 31076548, 31083561, 31090575, 31097591, 31104608, 31111627, 31118648, 31125670, 31132694, 31139719, 31146746, 31153775, 31160805, 31167837, 31174870, 31181905, 31188941, 31195979, 31203019, 31210060, 31217103, 31224148, 31231194, 31238241, 31245290, 31252341, 31259394, 31266448, 31273503, 31280560, 31287619, 31294679, 31301741, 31308805, 31315870, 31322937, 31330005, 31337075, 31344146, 31351220, 31358294, 31365371, 31372448, 31379528, 31386609, 31393692, 31400776, 31407862, 31414949, 31422038, 31429129, 31436221, 31443315, 31450411, 31457508, 31464606, 31471707, 31478809, 31485912, 31493017, 31500124, 31507232, 31514342, 31521454, 31528567, 31535681, 31542798, 31549916, 31557035, 31564156, 31571279, 31578403, 31585529, 31592657, 31599786, 31606917, 31614049, 31621183, 31628319, 31635456, 31642595, 31649735, 31656877, 31664021, 31671166, 31678313, 31685462, 31692612, 31699764, 31706917, 31714072, 31721229, 31728387, 31735547, 31742708, 31749871, 31757036, 31764202, 31771370, 31778539, 31785710, 31792883, 31800058, 31807234, 31814411, 31821590, 31828771, 31835954, 31843138, 31850323, 31857511, 31864700, 31871890, 31879082, 31886276, 31893472, 31900669, 31907867, 31915068, 31922270, 31929473, 31936678, 31943885, 31951094, 31958304, 31965515, 31972729, 31979944, 31987160, 31994378, 32001598, 32008820, 32016043, 32023268, 32030494, 32037722, 32044951, 32052183, 32059416, 32066650, 32073886, 32081124, 32088363, 32095604, 32102847, 32110091, 32117337, 32124585, 32131834, 32139085, 32146337, 32153592, 32160847, 32168105, 32175364, 32182624, 32189887, 32197151, 32204416, 32211684, 32218952, 32226223, 32233495, 32240769, 32248044, 32255321, 32262600, 32269880, 32277162, 32284446, 32291731, 32299018, 32306307, 32313597, 32320889, 32328182, 32335478, 32342774, 32350073, 32357373, 32364675, 32371978, 32379283, 32386590, 32393898, 32401208, 32408520, 32415833, 32423148, 32430465, 32437783, 32445103, 32452424, 32459747, 32467072, 32474399, 32481727, 32489057, 32496388, 32503721, 32511056, 32518392, 32525731, 32533070, 32540412, 32547755, 32555099, 32562446, 32569794, 32577143, 32584495, 32591848, 32599202, 32606559, 32613917, 32621276, 32628638, 32636001, 32643365, 32650732, 32658099, 32665469, 32672840, 32680213, 32687588, 32694964, 32702342, 32709722, 32717103, 32724486, 32731870, 32739257, 32746645, 32754034, 32761425, 32768818, 32776213, 32783609, 32791007, 32798407, 32805808, 32813211, 32820615, 32828022, 32835430, 32842839, 32850251, 32857664, 32865078, 32872495, 32879913, 32887332, 32894754, 32902177, 32909601, 32917028, 32924456, 32931885, 32939317, 32946750, 32954184, 32961621, 32969059, 32976499, 32983940, 32991383, 32998828, 33006275, 33013723, 33021173, 33028624, 33036077, 33043532, 33050989, 33058447, 33065907, 33073369, 33080832, 33088297, 33095764, 33103232, 33110702, 33118174, 33125647, 33133122, 33140599, 33148078, 33155558, 33163040, 33170523, 33178009, 33185495, 33192984, 33200474, 33207966, 33215460, 33222955, 33230453, 33237951, 33245452, 33252954, 33260458, 33267963, 33275470, 33282979, 33290490, 33298002, 33305516, 33313032, 33320549, 33328069, 33335589, 33343112, 33350636, 33358162, 33365689, 33373219, 33380750, 33388282, 33395817, 33403353, 33410891, 33418430, 33425971, 33433514, 33441059, 33448605, 33456153, 33463703, 33471254, 33478807, 33486362, 33493919, 33501477, 33509037, 33516598, 33524162, 33531727, 33539293, 33546862, 33554432 }; static uint32_t linear_slide_up(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { const uint32_t linear_slide_div = slide_value / 3072; const uint32_t linear_slide_mod = slide_value % 3072; const uint32_t linear_multiplier = avctx->linear_frequency_lut ? avctx->linear_frequency_lut[linear_slide_mod] : linear_frequency_lut[linear_slide_mod]; uint32_t new_frequency = ((uint64_t) linear_multiplier * frequency) >> (24 - linear_slide_div); if (new_frequency == frequency) new_frequency++; if (new_frequency < frequency) new_frequency = 0xFFFFFFFF; return (player_channel->frequency = new_frequency); } static uint32_t amiga_slide_up(AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { uint32_t new_frequency; uint64_t period = AVSEQ_SLIDE_CONST / frequency; const uint64_t slide = (uint64_t) slide_value << 32; if (period <= slide) period = slide + UINT64_C(0x100000000); period -= slide; new_frequency = AVSEQ_SLIDE_CONST / period; if (new_frequency == frequency) new_frequency++; if (new_frequency < frequency) new_frequency = 0xFFFFFFFF; return (player_channel->frequency = new_frequency); } static uint32_t linear_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { const uint32_t linear_slide_div = slide_value / 3072; const uint32_t linear_slide_mod = slide_value % 3072; uint32_t linear_multiplier = avctx->linear_frequency_lut ? avctx->linear_frequency_lut[-linear_slide_mod + 3072] : linear_frequency_lut[-linear_slide_mod + 3072]; uint32_t new_frequency = ((uint64_t) linear_multiplier * frequency) >> (25 + linear_slide_div); if (new_frequency == frequency) new_frequency--; if (new_frequency > frequency) new_frequency = 1; return (player_channel->frequency = new_frequency); } static uint32_t amiga_slide_down(AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { uint32_t new_frequency; uint64_t period = AVSEQ_SLIDE_CONST / frequency; const uint64_t slide = (uint64_t) slide_value << 32; period += slide; if (period < slide) period = UINT64_C(0xFFFFFFFF00000000); new_frequency = AVSEQ_SLIDE_CONST / period; if (new_frequency == frequency) new_frequency--; if (new_frequency > frequency) new_frequency = 1; return (player_channel->frequency = new_frequency); } -/** Note frequency lookup table. Value is 16777216*2^(x/12), where x=1 +/** Note frequency lookup table. Value is 16777216*2^(x/12), where x=0 equals note C-4. */ static const uint32_t pitch_lut[] = { 0x00F1A1BF, // B-3 0x01000000, // C-4 0x010F38F9, // C#4 0x011F59AC, // D-4 0x01306FE1, // D#4 0x01428A30, // E-4 0x0155B811, // F-4 0x016A09E6, // F#4 0x017F910D, // G-4 0x01965FEA, // G#4 0x01AE89FA, // A-4 0x01C823E0, // A#4 0x01E3437E, // B-4 0x02000000 // C-5 }; static uint32_t get_tone_pitch(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, int16_t note) { const AVSequencerSample *const sample = player_host_channel->sample; const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave = note / 12; int8_t finetune; note %= 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_host_channel->finetune) < 0) { note--; finetune += -0x80; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += ((int32_t) finetune * (int32_t) next_frequency) >> 7; return ((uint64_t) frequency * sample->rate) >> ((24+4) - octave); } static void portamento_slide_up(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint32_t data_word, const uint32_t carry_add, const uint32_t portamento_shift, const uint16_t channel) { if (player_channel->host_channel == channel) { uint32_t portamento_slide_value; const uint8_t portamento_sub_slide_value = data_word; if ((portamento_slide_value = ((data_word & 0xFFFFFF00) >> portamento_shift))) { player_host_channel->sub_slide += portamento_sub_slide_value; if (player_host_channel->sub_slide < portamento_sub_slide_value) portamento_slide_value += carry_add; if (player_channel->frequency) { if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_up(avctx, player_channel, player_channel->frequency, portamento_slide_value); else amiga_slide_up(player_channel, player_channel->frequency, portamento_slide_value); } } } } static void portamento_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint32_t data_word, const uint32_t carry_add, const uint32_t portamento_shift, const uint16_t channel) { if (player_channel->host_channel == channel) { uint32_t portamento_slide_value; const uint8_t portamento_sub_slide_value = data_word; if ((int32_t) data_word < 0) { portamento_slide_up(avctx, player_host_channel, player_channel, -data_word, carry_add, portamento_shift, channel); return; } if ((portamento_slide_value = ((data_word & 0xFFFFFF00) >> portamento_shift))) { if (player_host_channel->sub_slide < portamento_sub_slide_value) { portamento_slide_value += carry_add; if (portamento_slide_value < carry_add) portamento_slide_value = -1; } player_host_channel->sub_slide -= portamento_sub_slide_value; if (player_channel->frequency) { if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_down(avctx, player_channel, player_channel->frequency, portamento_slide_value); else amiga_slide_down(player_channel, player_channel->frequency, portamento_slide_value); } } } } static void portamento_up_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3, v4, v5, v8; v0 = player_host_channel->fine_porta_up; v1 = player_host_channel->fine_porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->porta_down = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->porta_up = data_word; player_host_channel->fine_porta_up = v0; player_host_channel->fine_porta_down = v1; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->fine_tone_porta; v4 = player_host_channel->tone_porta_once; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = v4; player_host_channel->fine_tone_porta_once = v8; } } static void portamento_down_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3, v4, v5, v8; v0 = player_host_channel->fine_porta_up; v1 = player_host_channel->fine_porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = data_word; v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->porta_up = data_word; v0 = v1; v3 = v4; v5 = v8; } player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = v0; player_host_channel->fine_porta_down = v1; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->fine_tone_porta; v3 = player_host_channel->tone_porta_once; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v0; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = v5; } } static void portamento_up_once_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3, v4, v5, v8; v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->porta_down_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->porta_up_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->fine_tone_porta; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = v4; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v8; } } static void portamento_down_once_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3, v4, v5, v8; v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = data_word; v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->porta_up_once = data_word; v0 = v1; v3 = v4; v5 = v8; } player_host_channel->porta_down_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->fine_tone_porta; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v3; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v5; } } static void do_vibrato(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const uint16_t vibrato_rate, int16_t vibrato_depth) { int32_t vibrato_slide_value; if (!vibrato_depth) vibrato_depth = player_host_channel->vibrato_depth; player_host_channel->vibrato_depth = vibrato_depth; vibrato_slide_value = ((-(int32_t) vibrato_depth * run_envelope(avctx, &player_host_channel->vibrato_env, vibrato_rate, 0)) >> (7 - 2)) << 8; if (player_channel->host_channel == channel) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency -= player_host_channel->vibrato_slide; portamento_slide_down(avctx, player_host_channel, player_channel, vibrato_slide_value, 1, 8, channel); player_host_channel->vibrato_slide -= old_frequency - player_channel->frequency; } } static uint32_t check_old_volume(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, uint16_t *const data_word, const uint16_t channel) { const AVSequencerSong *song; if (channel != player_channel->host_channel) return 0; song = avctx->player_song; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (*data_word < 0x4000) *data_word = ((*data_word & 0xFF00) << 2) | (*data_word & 0xFF); else *data_word = 0xFFFF; } return 1; } static void do_volume_slide(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, uint16_t data_word, const uint16_t channel) { if (check_old_volume(avctx, player_channel, &data_word, channel)) { uint16_t slide_volume = (player_channel->volume << 8U) + player_channel->sub_volume; if ((slide_volume += data_word) < data_word) slide_volume = 0xFFFF; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; } } static void do_volume_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, uint16_t data_word, const uint16_t channel) { if (check_old_volume(avctx, player_channel, &data_word, channel)) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (slide_volume < data_word) data_word = slide_volume; slide_volume -= data_word; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; } } static void volume_slide_up_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v3, v4, v5; v3 = player_host_channel->vol_slide_down; v4 = player_host_channel->fine_vol_slide_up; v5 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->vol_slide_up = data_word; player_host_channel->vol_slide_down = v3; player_host_channel->fine_vol_slide_up = v4; player_host_channel->fine_vol_slide_down = v5; } static void volume_slide_down_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v3, v4; v0 = player_host_channel->vol_slide_up; v3 = player_host_channel->fine_vol_slide_up; v4 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = data_word; player_host_channel->fine_vol_slide_up = v3; player_host_channel->fine_vol_slide_down = v4; } static void fine_volume_slide_up_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v4; v0 = player_host_channel->vol_slide_up; v1 = player_host_channel->vol_slide_down; v4 = player_host_channel->fine_vol_slide_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = v1; player_host_channel->fine_vol_slide_up = data_word; player_host_channel->fine_vol_slide_down = v4; } static void fine_volume_slide_down_ok(AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { const AVSequencerTrack *const track = player_host_channel->track; uint16_t v0, v1, v3; v0 = player_host_channel->vol_slide_up; v1 = player_host_channel->vol_slide_down; v3 = player_host_channel->fine_vol_slide_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->vol_slide_up = v0; player_host_channel->vol_slide_down = v1; player_host_channel->fine_vol_slide_up = data_word; player_host_channel->fine_vol_slide_down = v3; } static uint32_t check_old_track_volume(const AVSequencerContext *const avctx, uint16_t *data_word) { const AVSequencerSong *const song = avctx->player_song; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (*data_word < 0x4000) *data_word = ((*data_word & 0xFF00) << 2) | (*data_word & 0xFF); else *data_word = 0xFFFF; } return 1; } static void do_track_volume_slide(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if ((track_volume += data_word) < data_word) track_volume = 0xFFFF; player_host_channel->track_volume = track_volume >> 8; player_host_channel->track_sub_volume = track_volume; } } static void do_track_volume_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume < data_word) data_word = track_volume; track_volume -= data_word; player_host_channel->track_volume = track_volume >> 8; player_host_channel->track_sub_volume = track_volume; } } static void do_panning_slide(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, uint16_t data_word, const uint16_t channel) { if (player_channel->host_channel == channel) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < data_word) data_word = panning;
BastyCDGS/ffmpeg-soc
03e3535a8f2da3b11fe981a5b7c577431d22bde7
Fixed resetting of temp vars in (resonance) filters in both low and high quality mixer upon turning filtering off and on again.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index c84b0ea..0bd1983 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -5337,1326 +5337,1324 @@ CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center, mix_stereo_x_to_8_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_to_8_center, mix_stereo_backwards_32_to_8_center, mix_stereo_backwards_x_to_8_center }; static const void *mixer_stereo_surround_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_surround, mix_stereo_16_to_8_surround, mix_stereo_32_to_8_surround, mix_stereo_x_to_8_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_to_8_surround, mix_stereo_backwards_32_to_8_surround, mix_stereo_backwards_x_to_8_surround }; static void set_mix_functions(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { void **mix_func; void (*init_mixer_func)(const AV_HQMixerData *const mixer_data, struct ChannelBlock *channel_block, uint32_t volume, uint32_t panning); uint32_t panning = 0x80; if ((channel_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip_16_to_8; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono_16_to_8; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround_16_to_8; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } -static void update_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block) +static void update_sample_filter(const AV_HQMixerData *const mixer_data, AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { - channel_block->filter_c1 = 16777216; - channel_block->filter_c2 = 0; - channel_block->filter_c3 = 0; + channel_block->filter_c1 = 16777216; + channel_block->filter_c2 = 0; + channel_block->filter_c3 = 0; + channel_info->filter_tmp1 = 0; + channel_info->filter_tmp2 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; - - d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); + d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; - tmp = INT64_C(16777216) + d + e; - + tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } -static void set_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) +static void set_sample_filter(const AV_HQMixerData *const mixer_data, AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; - update_sample_filter(mixer_data, channel_block); + update_sample_filter(mixer_data, channel_info, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_HQMixerData *hq_mixer_data; AV_HQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned real16bit = 1, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(hq_mixer_data = av_mallocz(sizeof(AV_HQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(hq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mixer_data.mixctx = mixctx; buf_size = hq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=false;") || av_stristr(args, "real16bit=disabled;")) real16bit = 0; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->channel_info = channel_info; hq_mixer_data->mixer_data.channels_in = channels_in; hq_mixer_data->channels_in = channels_in; hq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mix_buf_size = mix_buf_mem_size; hq_mixer_data->buf = buf; hq_mixer_data->buf_size = buf_size; hq_mixer_data->mixer_data.mix_buf_size = hq_mixer_data->buf_size; hq_mixer_data->mixer_data.mix_buf = hq_mixer_data->buf; channel_rate = hq_mixer_data->mixer_data.mixctx->frequency; hq_mixer_data->mixer_data.rate = channel_rate; hq_mixer_data->mix_rate = channel_rate; hq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->filter_buf = buf; for (i = hq_mixer_data->channels_in; i > 0; i--) { - set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); - set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) hq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_HQMixerData *hq_mixer_data = (AV_HQMixerData *) mixer_data; if (!hq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->filter_buf); av_free(hq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t channel_rate = hq_mixer_data->mix_rate * 10; uint64_t pass_value; hq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) hq_mixer_data->mix_rate_frac >> 16); hq_mixer_data->pass_len = (uint64_t) pass_value / hq_mixer_data->mixer_data.tempo; hq_mixer_data->pass_len_frac = (((uint64_t) pass_value % hq_mixer_data->mixer_data.tempo) << 32) / hq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; hq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = hq_mixer_data->mixer_data.mix_buf_size; hq_mixer_data->mixer_data.channels_out = new_channels; if ((hq_mixer_data->buf_size * hq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = hq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = hq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return hq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return hq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); hq_mixer_data->mixer_data.mix_buf = buf; hq_mixer_data->mixer_data.mix_buf_size = buf_size; hq_mixer_data->filter_buf = filter_buf; } hq_mixer_data->channels_out = new_channels; hq_mixer_data->buf = hq_mixer_data->mixer_data.mix_buf; hq_mixer_data->buf_size = hq_mixer_data->mixer_data.mix_buf_size; if (hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (hq_mixer_data->mix_rate != mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; - update_sample_filter(hq_mixer_data, &channel_info->current); - update_sample_filter(hq_mixer_data, &channel_info->next); + update_sample_filter(hq_mixer_data, channel_info, &channel_info->current); + update_sample_filter(hq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { int32_t *volume_lut = hq_mixer_data->volume_lut; int32_t volume_mult = 0, volume_div = channels << 8; uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { - set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); - set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(hq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); + set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(hq_mixer_data, channel_block, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; - channel_info->filter_tmp1 = 0; - channel_info->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(hq_mixer_data, channel_block, 127, 0); + set_sample_filter(hq_mixer_data, channel_info, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(hq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); + set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; channel_info->prev_sample_r = 0; channel_info->curr_sample_r = 0; channel_info->next_sample_r = 0; set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(hq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); + set_sample_filter(hq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; - set_sample_filter(hq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); + set_sample_filter(hq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(hq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext high_quality_mixer = { .av_class = &avseq_high_quality_mixer_class, .name = "High quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for quality and supports advanced interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_HIGH_QUALITY_MIXER */ diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 2fad0a5..4a61394 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -3695,1320 +3695,1318 @@ CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center, mix_stereo_x_to_8_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_to_8_center, mix_stereo_backwards_32_to_8_center, mix_stereo_backwards_x_to_8_center }; static const void *mixer_stereo_surround_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_surround, mix_stereo_16_to_8_surround, mix_stereo_32_to_8_surround, mix_stereo_x_to_8_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_to_8_surround, mix_stereo_backwards_32_to_8_surround, mix_stereo_backwards_x_to_8_surround }; static void set_mix_functions(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { void **mix_func; void (*init_mixer_func)(const AV_LQMixerData *const mixer_data, struct ChannelBlock *channel_block, uint32_t volume, uint32_t panning); uint32_t panning = 0x80; if ((channel_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip_16_to_8; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono_16_to_8; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround_16_to_8; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } -static void update_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) +static void update_sample_filter(const AV_LQMixerData *const mixer_data, AV_LQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { - channel_block->filter_c1 = 16777216; - channel_block->filter_c2 = 0; - channel_block->filter_c3 = 0; + channel_block->filter_c1 = 16777216; + channel_block->filter_c2 = 0; + channel_block->filter_c3 = 0; + channel_info->filter_tmp1 = 0; + channel_info->filter_tmp2 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; - - d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); + d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; - tmp = INT64_C(16777216) + d + e; - + tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } -static void set_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) +static void set_sample_filter(const AV_LQMixerData *const mixer_data, AV_LQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; - update_sample_filter(mixer_data, channel_block); + update_sample_filter(mixer_data, channel_info, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_LQMixerData *lq_mixer_data; AV_LQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned interpolation = 0, real16bit = 0, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(lq_mixer_data = av_mallocz(sizeof(AV_LQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(lq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mixer_data.mixctx = mixctx; buf_size = lq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=true;") || av_stristr(args, "real16bit=enabled;")) real16bit = 1; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (av_stristr(args, "interpolation=true;") || av_stristr(args, "interpolation=enabled;")) interpolation = 2; else if ((cfg_buf = av_stristr(args, "interpolation="))) sscanf(cfg_buf, "interpolation=%d;", &interpolation); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->channel_info = channel_info; lq_mixer_data->mixer_data.channels_in = channels_in; lq_mixer_data->channels_in = channels_in; lq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mix_buf_size = mix_buf_mem_size; lq_mixer_data->buf = buf; lq_mixer_data->buf_size = buf_size; lq_mixer_data->mixer_data.mix_buf_size = lq_mixer_data->buf_size; lq_mixer_data->mixer_data.mix_buf = lq_mixer_data->buf; channel_rate = lq_mixer_data->mixer_data.mixctx->frequency; lq_mixer_data->mixer_data.rate = channel_rate; lq_mixer_data->mix_rate = channel_rate; lq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; lq_mixer_data->interpolation = interpolation >= 2 ? 2 : interpolation; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->filter_buf = buf; for (i = lq_mixer_data->channels_in; i > 0; i--) { - set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); - set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) lq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_LQMixerData *lq_mixer_data = (AV_LQMixerData *) mixer_data; if (!lq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->filter_buf); av_free(lq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t channel_rate = lq_mixer_data->mix_rate * 10; uint64_t pass_value; lq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) lq_mixer_data->mix_rate_frac >> 16); lq_mixer_data->pass_len = (uint64_t) pass_value / lq_mixer_data->mixer_data.tempo; lq_mixer_data->pass_len_frac = (((uint64_t) pass_value % lq_mixer_data->mixer_data.tempo) << 32) / lq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; lq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = lq_mixer_data->mixer_data.mix_buf_size; lq_mixer_data->mixer_data.channels_out = new_channels; if ((lq_mixer_data->buf_size * lq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = lq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = lq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return lq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return lq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); lq_mixer_data->mixer_data.mix_buf = buf; lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = new_channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; - update_sample_filter(lq_mixer_data, &channel_info->current); - update_sample_filter(lq_mixer_data, &channel_info->next); + update_sample_filter(lq_mixer_data, channel_info, &channel_info->current); + update_sample_filter(lq_mixer_data, channel_info, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = lq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { int32_t *volume_lut = lq_mixer_data->volume_lut; int32_t volume_mult = 0, volume_div = channels << 8; uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { - set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); - set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(lq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); + set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(lq_mixer_data, channel_block, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; - channel_info->filter_tmp1 = 0; - channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(lq_mixer_data, channel_block, 127, 0); + set_sample_filter(lq_mixer_data, channel_info, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(lq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); + set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); - set_sample_filter(lq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); + set_sample_filter(lq_mixer_data, channel_info, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; - set_sample_filter(lq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); + set_sample_filter(lq_mixer_data, channel_info, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } static av_cold void mix_parallel(AVMixerData *mixer_data, int32_t *buf, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample_parallel(lq_mixer_data, buf, mix_len, first_channel, last_channel); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, .mix_parallel = mix_parallel, }; #endif /* CONFIG_LOW_QUALITY_MIXER */
BastyCDGS/ffmpeg-soc
a12f71cb2634b8f05cd290e30aad6c17ff374211
Fixed linear interpolation in low quality mixer for backwards looping samples and samples with bit depth != 8 && != 16 && != 32.
diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 2fd9da3..2fad0a5 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -116,3565 +116,3996 @@ static void apply_filter(AV_LQMixerChannelInfo *const channel_info, struct Chann mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } static void mix_sample_parallel(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len, const uint32_t first_channel, const uint32_t last_channel) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info + first_channel; uint16_t i = (last_channel - first_channel) + 1; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted++; if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } #define MIX_FUNCTION(INIT, TYPE, OP1, OP2, OFFSET_START, OFFSET_END, \ - SKIP, NEXTS, NEXTA, SHIFTS, SHIFTN, SHIFTB) \ + SKIP, NEXTS, NEXTA, NEXTI, SHIFTS, SHIFTN, SHIFTB) \ const TYPE *sample = (const TYPE *) channel_block->data; \ int32_t *mix_buf = *buf; \ uint32_t curr_offset = *offset; \ uint32_t curr_frac = *fraction; \ uint32_t i; \ INIT; \ \ if (advance) { \ if (mixer_data->interpolation) { \ int32_t smp; \ int32_t interpolate_div; \ \ OFFSET_START; \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_advance_interpolated_sample; \ \ i--; \ \ do { \ uint32_t interpolate_offset = advance; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) \ interpolate_offset++; \ \ smp = 0; \ interpolate_div = 0; \ \ do { \ NEXTA; \ interpolate_div++; \ } while (--interpolate_offset); \ \ smp /= interpolate_div; \ SHIFTS; \ get_second_advance_interpolated_sample: \ interpolate_offset = advance; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) \ interpolate_offset++; \ \ smp = 0; \ interpolate_div = 0; \ \ do { \ NEXTA; \ interpolate_div++; \ } while (--interpolate_offset); \ \ smp /= interpolate_div; \ SHIFTS; \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } else { \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_advance_sample; \ \ i--; \ \ do { \ SKIP; \ curr_frac += adv_frac; \ curr_offset OP1 advance; \ \ if (curr_frac < adv_frac) \ curr_offset OP2; \ get_second_advance_sample: \ SKIP; \ curr_frac += adv_frac; \ curr_offset OP1 advance; \ \ if (curr_frac < adv_frac) \ curr_offset OP2; \ } while (--i); \ \ *buf = mix_buf; \ *offset = curr_offset; \ *fraction = curr_frac; \ } \ } else { \ int32_t smp; \ \ if (mixer_data->interpolation > 1) { \ uint32_t interpolate_frac, interpolate_count; \ int32_t interpolate_div; \ int64_t smp_value; \ \ OFFSET_START; \ NEXTS; \ smp_value = 0; \ \ - if (len) \ - smp_value = (*sample - smp) * (int64_t) adv_frac; \ + if (len > 1) { \ + NEXTI; \ + } \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_interpolated_sample; \ \ i--; \ \ do { \ SHIFTS; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ NEXTS; \ - smp_value = 0; \ - \ - if (len) \ - smp_value = (*sample - smp) * (int64_t) adv_frac; \ + NEXTI; \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ } else { \ smp += interpolate_div; \ interpolate_count += interpolate_frac; \ \ if (interpolate_count < interpolate_frac) { \ smp++; \ \ if (interpolate_div < 0) \ smp -= 2; \ } \ } \ get_second_interpolated_sample: \ SHIFTS; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ NEXTS; \ smp_value = 0; \ \ - if (len) \ - smp_value = (*sample - smp) * (int64_t) adv_frac; \ + if (i > 1) { \ + NEXTI; \ + } \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ } else { \ smp += interpolate_div; \ interpolate_count += interpolate_frac; \ \ if (interpolate_count < interpolate_frac) { \ smp++; \ \ if (interpolate_div < 0) \ smp -= 2; \ } \ } \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } else { \ OFFSET_START; \ SHIFTN; \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_sample; \ \ i--; \ \ do { \ SHIFTB; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ SHIFTN; \ } \ get_second_sample: \ SHIFTB; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ SHIFTN; \ } \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } \ } #define MIX(type) \ static void mix_##type(const AV_LQMixerData *const mixer_data, \ const struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *sample++], *mix_buf++ += smp) } MIX(mono_backwards_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *--sample], *mix_buf++ += smp) } MIX(mono_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf++ += smp) } MIX(mono_backwards_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *--sample >> 8], *mix_buf++ += smp) } MIX(mono_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf++ += smp) } MIX(mono_backwards_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *--sample >> 24], *mix_buf++ += smp) } MIX(mono_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp) } MIX(mono_backwards_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp) } MIX(mono_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(mono_backwards_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp) } MIX(stereo_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int8_t smp_in; int32_t smp_right; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += volume_left_lut[(uint8_t) smp]; *mix_buf++ += volume_right_lut[(uint8_t) smp], smp_in = *sample++; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int8_t smp_in; int32_t smp_right; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += volume_left_lut[(uint8_t) smp]; *mix_buf++ += volume_right_lut[(uint8_t) smp], smp_in = *--sample; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_16_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int16_t smp_in; int32_t smp_right; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = (uint16_t) sample[curr_offset] >> 8; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = (uint16_t) smp >> 8; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp_in = (uint16_t) *sample++ >> 8; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_16_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int16_t smp_in; int32_t smp_right; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = (uint16_t) sample[curr_offset] >> 8; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = (uint16_t) smp >> 8; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp_in = (uint16_t) *--sample >> 8; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_32_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int32_t smp_in; int32_t smp_right; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = (uint32_t) sample[curr_offset] >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = (uint32_t) smp >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp_in = (uint32_t) *sample++ >> 24; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_32_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int32_t smp_in; int32_t smp_right; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = (uint32_t) sample[curr_offset] >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = (uint32_t) smp >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], smp_in = (uint32_t) *--sample >> 24; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_x_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int32_t smp_in; int32_t smp_right; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = (uint32_t) smp_data >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = (uint32_t) smp >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = (uint32_t) smp_data >> 24; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_x_to_8) { MIX_FUNCTION(const int32_t *const volume_left_lut = channel_block->volume_left_lut; const int32_t *const volume_right_lut = channel_block->volume_right_lut; int32_t smp_in; int32_t smp_right; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = (uint32_t) smp_data >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = (uint32_t) smp >> 24; *mix_buf++ += volume_left_lut[(uint8_t) smp_in]; *mix_buf++ += volume_right_lut[(uint8_t) smp_in], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = (uint32_t) smp_data >> 24; smp = volume_left_lut[(uint8_t) smp_in]; smp_right = volume_right_lut[(uint8_t) smp_in], *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int16_t smp_in; int32_t smp_right; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp_in = *sample++; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_16) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int16_t smp_in; int32_t smp_right; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp_in = *--sample; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; int32_t smp_right; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp_in = *sample++; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_32) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; int32_t smp_right; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = sample[curr_offset]; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp_in = *--sample; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; int32_t smp_right; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = smp_data; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = smp_data; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_backwards_x) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; int32_t smp_right; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = smp_data; *mix_buf++ += ((int64_t) smp_in * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp_in * mult_right_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf++ += ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = smp_data; smp = ((int64_t) smp_in * mult_left_volume) / div_volume; smp_right = ((int64_t) smp_in * mult_right_volume) / div_volume, *mix_buf++ += smp; *mix_buf++ += smp_right) } MIX(stereo_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint8_t) sample[curr_offset]]; mix_buf += 2, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint8_t) smp]; mix_buf += 2, smp = volume_lut[(uint8_t) *sample++], *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint8_t) sample[curr_offset]]; mix_buf += 2, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint8_t) smp]; mix_buf += 2, smp = volume_lut[(uint8_t) *--sample], *mix_buf += smp; mix_buf += 2) } MIX(stereo_16_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint16_t) sample[curr_offset] >> 8]; mix_buf += 2, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint16_t) smp >> 8]; mix_buf += 2, smp = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_16_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint16_t) sample[curr_offset] >> 8]; mix_buf += 2, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint16_t) smp >> 8]; mix_buf += 2, smp = volume_lut[(uint16_t) *--sample >> 8], *mix_buf += smp; mix_buf += 2) } MIX(stereo_32_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint32_t) sample[curr_offset] >> 24]; mix_buf += 2, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint32_t) smp >> 24]; mix_buf += 2, smp = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_32_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += volume_lut[(uint32_t) sample[curr_offset] >> 24]; mix_buf += 2, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint32_t) smp >> 24]; mix_buf += 2, smp = volume_lut[(uint32_t) *--sample >> 24], *mix_buf += smp; mix_buf += 2) } MIX(stereo_x_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf += volume_lut[(uint32_t) smp_data >> 24]; mix_buf += 2, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint32_t) smp >> 24]; mix_buf += 2, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_x_to_8_left) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf += volume_lut[(uint32_t) smp_data >> 24]; mix_buf += 2, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf += volume_lut[(uint32_t) smp >> 24]; mix_buf += 2, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf += smp; mix_buf += 2) } MIX(stereo_16_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; mix_buf += 2, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_16_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; mix_buf += 2, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_32_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; mix_buf += 2, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, smp = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_32_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf += ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; mix_buf += 2, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, smp = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_x_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; mix_buf += 2, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_backwards_x_left) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf += ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; mix_buf += 2, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, *mix_buf += ((int64_t) smp * mult_left_volume) / div_volume; mix_buf += 2, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf += smp; mix_buf += 2) } MIX(stereo_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *sample++], mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *--sample], mix_buf++; *mix_buf++ += smp) } MIX(stereo_16_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *sample++ >> 8], mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_16_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *--sample >> 8], mix_buf++; *mix_buf++ += smp) } MIX(stereo_32_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *sample++ >> 24], mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_32_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *--sample >> 24], mix_buf++; *mix_buf++ += smp) } MIX(stereo_x_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = volume_lut[(uint32_t) smp_data >> 24], mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_x_to_8_right) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_right_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += volume_lut[(uint32_t) smp >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24], mix_buf++; *mix_buf++ += smp) } MIX(stereo_16_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += ((int64_t) sample[curr_offset] * mult_right_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp = ((int64_t) *sample++ * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_16_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += ((int64_t) sample[curr_offset] * mult_right_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp = ((int64_t) *--sample * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_32_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += ((int64_t) sample[curr_offset] * mult_right_volume) / div_volume, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp = ((int64_t) *sample++ * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_32_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, mix_buf++; *mix_buf++ += ((int64_t) sample[curr_offset] * mult_right_volume) / div_volume, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, smp = ((int64_t) *--sample * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_x_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } mix_buf++; *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_right_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = ((int64_t) ((int32_t) smp_data) * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_backwards_x_right) { MIX_FUNCTION(const int32_t mult_right_volume = channel_block->mult_right_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } mix_buf++; *mix_buf++ += ((int64_t) ((int32_t) smp_data) * mult_right_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, mix_buf++; *mix_buf++ += ((int64_t) smp * mult_right_volume) / div_volume, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) ((int32_t) smp_data) * mult_right_volume) / div_volume, mix_buf++; *mix_buf++ += smp) } MIX(stereo_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint8_t) sample[curr_offset]]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint8_t) smp]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint8_t) *sample++], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint8_t) sample[curr_offset]]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint8_t) smp]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint8_t) *--sample], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_16_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint16_t) sample[curr_offset] >> 8]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint16_t) smp >> 8]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_16_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint16_t) sample[curr_offset] >> 8]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint16_t) smp >> 8]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint16_t) *--sample >> 8], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_32_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint32_t) sample[curr_offset] >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_32_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint32_t) sample[curr_offset] >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = volume_lut[(uint32_t) *--sample >> 24], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_x_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_x_to_8_center) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_16_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_16_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_32_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_32_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, smp_in = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_x_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_backwards_x_center) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += smp_in) } MIX(stereo_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint8_t) sample[curr_offset]]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint8_t) smp]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint8_t) *sample++], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint8_t) sample[curr_offset]]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint8_t) smp]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint8_t) *--sample], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_16_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint16_t) sample[curr_offset] >> 8]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint16_t) smp >> 8]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_16_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint16_t) sample[curr_offset] >> 8]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint16_t) smp >> 8]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint16_t) *--sample >> 8], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_32_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint32_t) sample[curr_offset] >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_32_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = volume_lut[(uint32_t) sample[curr_offset] >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = volume_lut[(uint32_t) *--sample >> 24], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_x_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_x_to_8_surround) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = volume_lut[(uint32_t) smp >> 24]; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_16_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_16_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_32_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *sample++, smp += *sample++, + smp_value = (*sample - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = ((int64_t) *sample++ * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_32_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, smp_in = ((int64_t) sample[curr_offset] * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp = *--sample, smp += *--sample, + smp_value = (*(sample-1) - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, smp_in = ((int64_t) *--sample * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_x_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, + if (((bit &= 31) + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample++ << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } MIX(stereo_backwards_x_surround) { MIX_FUNCTION(const int32_t mult_left_volume = channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp_in; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, + smp_value = bits_per_sample; + bit -= bits_per_sample; + + if ((int32_t) bit < 0) { + bit &= 31; + + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *(sample-1) << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *(sample-1) << bit; + smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } else { + if ((bit + bits_per_sample) < 32) { + smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); + } else { + smp_data = (uint32_t) *sample << bit; + smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); + } + } + + bit = smp_value; + smp_value = (smp_data - smp) * (int64_t) adv_frac, smp_in = ((int64_t) smp * mult_left_volume) / div_volume; *mix_buf++ += smp_in; *mix_buf++ += ~smp_in, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp_in = ((int64_t) ((int32_t) smp_data) * mult_left_volume) / div_volume, *mix_buf++ += smp_in; *mix_buf++ += ~smp_in) } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_LQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = left_volume * mixer_data->amplify; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center, mix_stereo_x_to_8_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_to_8_center, mix_stereo_backwards_32_to_8_center, mix_stereo_backwards_x_to_8_center }; static const void *mixer_stereo_surround_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_surround, mix_stereo_16_to_8_surround, mix_stereo_32_to_8_surround, mix_stereo_x_to_8_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_to_8_surround, mix_stereo_backwards_32_to_8_surround, mix_stereo_backwards_x_to_8_surround }; static void set_mix_functions(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { void **mix_func; void (*init_mixer_func)(const AV_LQMixerData *const mixer_data, struct ChannelBlock *channel_block, uint32_t volume, uint32_t panning); uint32_t panning = 0x80; if ((channel_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip_16_to_8; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono_16_to_8; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround_16_to_8; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855),
BastyCDGS/ffmpeg-soc
cf101b013b1f6a09f6deb0f2f840a156705e7899
Fixed some nits in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index b734eba..c84b0ea 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1627,2219 +1627,2191 @@ static void get_backwards_next_sample_16(const AV_HQMixerData *const mixer_data, if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *const sample = (const int8_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { - if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - } else if (channel_next_block->bits_per_sample == 16) { - return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - } else if (channel_next_block->bits_per_sample == 32) { - return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - } else { - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); - } + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { + if (channel_next_block->bits_per_sample == 16) + return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + else if (channel_next_block->bits_per_sample == 32) + return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + else + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + } else if (channel_next_block->bits_per_sample == 16) { + return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + } else if (channel_next_block->bits_per_sample == 32) { + return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + } else { + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } - - sample = (const int8_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; } + + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { - if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } else if (channel_next_block->bits_per_sample == 16) { - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } else if (channel_next_block->bits_per_sample == 32) { - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } else { - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { + if (channel_next_block->bits_per_sample == 16) + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 32) + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + } else if (channel_next_block->bits_per_sample == 16) { + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + } else if (channel_next_block->bits_per_sample == 32) { + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + } else { + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } - - sample = (const int8_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; } + + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int16_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 32) + return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int16_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 32) + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 16) + return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 16) + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } + } else if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + bits_per_sample = channel_next_block->bits_per_sample; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; } else { - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - bits_per_sample = channel_next_block->bits_per_sample; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; - } + offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } + } else if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + bits_per_sample = channel_next_block->bits_per_sample; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; } else { - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - bits_per_sample = channel_next_block->bits_per_sample; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; - } + offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 32) + return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 32) + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 16) + return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset -= restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } - } else { - if (channel_next_block->data) { - if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { - if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); - } - - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; + } else if (channel_next_block->data) { + if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { + if (channel_next_block->bits_per_sample == 8) + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else if (channel_next_block->bits_per_sample == 16) + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); + else + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } + + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; + } else { + offset += restart_offset; } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } + } else if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + bits_per_sample = channel_next_block->bits_per_sample; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; } else { - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - bits_per_sample = channel_next_block->bits_per_sample; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset -= restart_offset; - } + offset -= restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } + } else if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + bits_per_sample = channel_next_block->bits_per_sample; + offset = channel_next_block->offset + (offset - end_offset); + end_offset = channel_next_block->end_offset; + restart_offset = channel_next_block->restart_offset; + count_restart = channel_next_block->count_restart; + counted = channel_next_block->counted; + channel_block = channel_next_block; } else { - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - bits_per_sample = channel_next_block->bits_per_sample; - offset = channel_next_block->offset + (offset - end_offset); - end_offset = channel_next_block->end_offset; - restart_offset = channel_next_block->restart_offset; - count_restart = channel_next_block->count_restart; - counted = channel_next_block->counted; - channel_block = channel_next_block; - } else { - offset += restart_offset; - } + offset += restart_offset; } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8;
BastyCDGS/ffmpeg-soc
64358c808f51845a63f7afa0092a9e491fac1158
Fixed volume calculation for real 16-bit modes for getting next sample in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index cb6014f..b734eba 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -2350,1504 +2350,1504 @@ static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, cons } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; - div_volume = channel_block->div_volume; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) {
BastyCDGS/ffmpeg-soc
284de9c72c479ec580c07b911f016b511a5fdf7b
Fixed start sample calculation when new bit depth is used as next sample in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index c999b15..cb6014f 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1722,1974 +1722,1974 @@ static void get_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) get_backwards_next_sample_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 16) get_backwards_next_sample_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else get_backwards_next_sample_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); return; } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } } } else { struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *const sample = (const int8_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *const sample = (const int16_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *const sample = (const int32_t *const) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else if (channel_next_block->bits_per_sample == 32) return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); else return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 16) { return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else if (channel_next_block->bits_per_sample == 32) { return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } else { return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset); static int32_t get_backwards_sample_1_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if ((channel_next_block->bits_per_sample <= 8) || !mixer_data->real_16_bit_mode) { if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 16) { - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else if (channel_next_block->bits_per_sample == 32) { - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } else { - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } } sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x_to_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 32) - return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_32(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *channel_next_block = &channel_info->next; if (channel_next_block->data) { if (channel_block->bits_per_sample != channel_next_block->bits_per_sample) { if (channel_next_block->bits_per_sample == 8) - return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_8(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else if (channel_next_block->bits_per_sample == 16) - return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_16(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); else - return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset); + return get_backwards_sample_1_x(mixer_data, channel_info, channel_next_block, channel_next_block->offset + (offset - end_offset)); } sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset -= restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t count_restart = channel_block->count_restart; uint32_t counted = channel_block->counted; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (count_restart && (count_restart == ++counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } else { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { offset += restart_offset; } } } else { const struct ChannelBlock *const channel_next_block = &channel_info->next; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; div_volume = channel_block->div_volume; bits_per_sample = channel_next_block->bits_per_sample; offset = channel_next_block->offset + (offset - end_offset); end_offset = channel_next_block->end_offset; restart_offset = channel_next_block->restart_offset; count_restart = channel_next_block->count_restart; counted = channel_next_block->counted; channel_block = channel_next_block; } else { return 0; } } } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(mixer_data, channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(mixer_data, channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const AV_HQMixerData *const mixer_data, const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(mixer_data, channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample;
BastyCDGS/ffmpeg-soc
3b0f67603e16979e3a7aea724455bec2fe0b60fc
Some small nit fixes in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 102dc0a..8bd6f51 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1367,2651 +1367,2651 @@ static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; - smp = (uint32_t) curr_frac >> 1; + smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; - smp = (uint32_t) curr_frac >> 1; + smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; - smp = (uint32_t) curr_frac >> 1; + smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; - smp = (uint32_t) curr_frac >> 1; + smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_surround_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; - smp = (uint32_t) curr_frac >> 1; + smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += ~smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_surround(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += ~smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_HQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = left_volume * mixer_data->amplify; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center,
BastyCDGS/ffmpeg-soc
22da89a922416f4ff17cb658e937a8814096a347
Fixed some nits.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 68e998e..225159d 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1183,2652 +1183,2652 @@ static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const chan sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - *mix_buf++ += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); + *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~curr_frac; + int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - *mix_buf += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); + *mix_buf += (interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~curr_frac; + int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; - *mix_buf++ += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); + *mix_buf++ += (interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~curr_frac; + int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - smp = ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); + smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_surround_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += ~smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_surround(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~curr_frac; + int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - smp = ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); + smp = (interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += ~smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_HQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = left_volume * mixer_data->amplify; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center,
BastyCDGS/ffmpeg-soc
85c1a4ce8eedd237684d7df910fe6b0fc181a95a
Fixed distortion in high quality mixer introduced by last commit.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 1735afb..68e998e 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1160,2675 +1160,2675 @@ static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~(uint64_t) curr_frac; + int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = (uint32_t) ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += UINT64_C(0x100000000); + interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += UINT64_C(0x100000000); + interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - *mix_buf++ += (interpolate_div << 32) / interpolate_frac; + *mix_buf++ += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~(uint64_t) curr_frac; + int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - *mix_buf += (interpolate_div << 32) / interpolate_frac; + *mix_buf += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~(uint64_t) curr_frac; + int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; - *mix_buf++ += (interpolate_div << 32) / interpolate_frac; + *mix_buf++ += ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~(uint64_t) curr_frac; + int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - smp = (interpolate_div << 32) / interpolate_frac; + smp = ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_surround_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += ~smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_surround(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; - int64_t interpolate_frac = ~(uint64_t) curr_frac; + int64_t interpolate_div = ((int64_t) ((uint32_t) ~curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += INT64_C(0x100000000); interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac; interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); - smp = (interpolate_div << 32) / interpolate_frac; + smp = ((int64_t) interpolate_div << 24) / (interpolate_frac >> 8); *mix_buf++ += smp; *mix_buf++ += ~smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_HQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = left_volume * mixer_data->amplify; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center,
BastyCDGS/ffmpeg-soc
632f53aad640b5bda1da26568ef9e2a73cfa5fbb
Fixed player random envelope handling, improved quality of high quality mixer and added (resonance) filter default definitions to instruments.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 9b68f9a..1735afb 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1119,2716 +1119,2716 @@ static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { - int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); - int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; + int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); + int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; - smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; - smp = smp_value + interpolate_div; + smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; + smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; - int32_t interpolate_frac = ~curr_frac >> 8; + int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~(uint64_t) curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += UINT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += UINT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); - interpolate_frac += curr_frac >> 8; - interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); - *mix_buf++ += ((int64_t) interpolate_div << 32) / interpolate_frac; + interpolate_frac += curr_frac; + interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); + *mix_buf++ += (interpolate_div << 32) / interpolate_frac; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { - int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); - int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; + int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); + int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; - smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; - smp = smp_value + interpolate_div; + smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; + smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; - int32_t interpolate_frac = ~curr_frac >> 8; + int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~(uint64_t) curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); - interpolate_frac += curr_frac >> 8; - interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); - *mix_buf += ((int64_t) interpolate_div << 32) / interpolate_frac; + interpolate_frac += curr_frac; + interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); + *mix_buf += (interpolate_div << 32) / interpolate_frac; mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_right_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { - int32_t interpolate_frac = -(channel_info->prev_sample_r - channel_info->curr_sample_r); - int32_t interpolate_div = (channel_info->next_sample_r - (channel_info->curr_sample_r + interpolate_frac)) >> 2; + int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); + int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; - smp_value = (channel_info->prev_sample_r + channel_info->curr_sample_r) >> 1; - smp = smp_value + interpolate_div; + smp_value = ((int64_t) channel_info->prev_sample_r + (int64_t) channel_info->curr_sample_r) >> 1; + smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample_r; mix_buf++; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample_r = channel_info->curr_sample_r; channel_info->curr_sample_r = channel_info->next_sample_r; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_right(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; - int32_t interpolate_frac = ~curr_frac >> 8; + int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~(uint64_t) curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); - interpolate_frac += curr_frac >> 8; - interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); + interpolate_frac += curr_frac; + interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); mix_buf++; - *mix_buf++ += ((int64_t) interpolate_div << 32) / interpolate_frac; + *mix_buf++ += (interpolate_div << 32) / interpolate_frac; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_right) { channel_info->mix_right = 1; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x_to_8) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_16) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_16(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_32) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_32(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, 1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } MIX(stereo_backwards_x) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_left(mixer_data, channel_info, channel_block, &mix_buf, get_curr_sample_func, get_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; mix_average_right(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, &mix_buf, get_next_sample_func, -1, &curr_offset, &curr_frac, advance, adv_frac, len); channel_info->mix_right = 1; channel_info->curr_sample_r = get_curr_sample_x(channel_info, channel_block, *offset); mix_right_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } channel_info->mix_right = 0; } static void mix_center_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { - int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); - int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; + int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); + int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; - smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; - smp = smp_value + interpolate_div; + smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; + smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_center(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; - int32_t interpolate_frac = ~curr_frac >> 8; + int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~(uint64_t) curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); - interpolate_frac += curr_frac >> 8; - interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); - smp = ((int64_t) interpolate_div << 32) / interpolate_frac; + interpolate_frac += curr_frac; + interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); + smp = (interpolate_div << 32) / interpolate_frac; *mix_buf++ += smp; *mix_buf++ += smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_center) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_center(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_center_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_surround_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { - int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); - int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; + int64_t interpolate_frac = -((int64_t) channel_info->prev_sample - (int64_t) channel_info->curr_sample); + int64_t interpolate_div = ((int64_t) channel_info->next_sample - ((int64_t) channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; - smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; - smp = smp_value + interpolate_div; + smp_value = ((int64_t) channel_info->prev_sample + (int64_t) channel_info->curr_sample) >> 1; + smp = (uint32_t) smp_value + (uint32_t) interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; *mix_buf++ += ~smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_surround(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); - int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; - int32_t interpolate_frac = ~curr_frac >> 8; + int64_t interpolate_div = ((int64_t) (~(uint64_t) curr_frac >> 1) * smp) >> 31; + int64_t interpolate_frac = ~(uint64_t) curr_frac; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { - interpolate_frac += 0x1000000; - interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; + interpolate_frac += INT64_C(0x100000000); + interpolate_div += get_sample_func(channel_info, channel_block, curr_offset); curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); - interpolate_frac += curr_frac >> 8; - interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); - smp = ((int64_t) interpolate_div << 32) / interpolate_frac; + interpolate_frac += curr_frac; + interpolate_div += (((int64_t) ((uint32_t) curr_frac >> 1) * smp) >> 31); + smp = (interpolate_div << 32) / interpolate_frac; *mix_buf++ += smp; *mix_buf++ += ~smp; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_surround) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_surround(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_surround_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } #define CHANNEL_PREPARE(type) \ static void channel_prepare_##type(const AV_HQMixerData *const mixer_data, \ struct ChannelBlock *const channel_block, \ uint32_t volume, \ uint32_t panning) CHANNEL_PREPARE(skip) { } CHANNEL_PREPARE(stereo_8) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 16; left_volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + left_volume; volume = ((panning * mixer_data->mixer_data.volume_right * volume) >> 16) & 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 8; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 8; volume &= 0xFF00; channel_block->volume_right_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_8_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 9; volume &= 0xFF00; channel_block->volume_left_lut = mixer_data->volume_lut + volume; } CHANNEL_PREPARE(stereo_16) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = left_volume * mixer_data->amplify; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_16_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = volume * mixer_data->amplify; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 8; } CHANNEL_PREPARE(stereo_32) { uint32_t left_volume = 255 - panning; left_volume *= mixer_data->mixer_data.volume_left * volume; left_volume >>= 24; channel_block->mult_left_volume = (left_volume * mixer_data->amplify) >> 8; volume = (panning * mixer_data->mixer_data.volume_right * volume) >> 24; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_left) { volume *= mixer_data->mixer_data.volume_left; volume >>= 16; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_right) { volume *= mixer_data->mixer_data.volume_right; volume >>= 16; channel_block->mult_right_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } CHANNEL_PREPARE(stereo_32_center) { volume *= mixer_data->mixer_data.volume_left; volume >>= 17; channel_block->mult_left_volume = (volume * mixer_data->amplify) >> 8; channel_block->div_volume = (uint32_t) mixer_data->channels_in << 16; } static const void *mixer_skip[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_mono_8, mix_mono_16, mix_mono_32, mix_mono_x, mix_mono_backwards_8, mix_mono_backwards_16, mix_mono_backwards_32, mix_mono_backwards_x }; static const void *mixer_stereo[] = { channel_prepare_stereo_8, channel_prepare_stereo_16, channel_prepare_stereo_32, mix_stereo_8, mix_stereo_16, mix_stereo_32, mix_stereo_x, mix_stereo_backwards_8, mix_stereo_backwards_16, mix_stereo_backwards_32, mix_stereo_backwards_x }; static const void *mixer_stereo_left[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_16_left, channel_prepare_stereo_32_left, mix_stereo_8_left, mix_stereo_16_left, mix_stereo_32_left, mix_stereo_x_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_left, mix_stereo_backwards_32_left, mix_stereo_backwards_x_left }; static const void *mixer_stereo_right[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_16_right, channel_prepare_stereo_32_right, mix_stereo_8_right, mix_stereo_16_right, mix_stereo_32_right, mix_stereo_x_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_right, mix_stereo_backwards_32_right, mix_stereo_backwards_x_right }; static const void *mixer_stereo_center[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_center, mix_stereo_16_center, mix_stereo_32_center, mix_stereo_x_center, mix_stereo_backwards_8_center, mix_stereo_backwards_16_center, mix_stereo_backwards_32_center, mix_stereo_backwards_x_center }; static const void *mixer_stereo_surround[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_16_center, channel_prepare_stereo_32_center, mix_stereo_8_surround, mix_stereo_16_surround, mix_stereo_32_surround, mix_stereo_x_surround, mix_stereo_backwards_8_surround, mix_stereo_backwards_16_surround, mix_stereo_backwards_32_surround, mix_stereo_backwards_x_surround }; static const void *mixer_skip_16_to_8[] = { channel_prepare_skip, channel_prepare_skip, channel_prepare_skip, mix_skip, mix_skip, mix_skip, mix_skip, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards, mix_skip_backwards }; static const void *mixer_mono_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_mono_8, mix_mono_16_to_8, mix_mono_32_to_8, mix_mono_x_to_8, mix_mono_backwards_8, mix_mono_backwards_16_to_8, mix_mono_backwards_32_to_8, mix_mono_backwards_x_to_8 }; static const void *mixer_stereo_16_to_8[] = { channel_prepare_stereo_8, channel_prepare_stereo_8, channel_prepare_stereo_8, mix_stereo_8, mix_stereo_16_to_8, mix_stereo_32_to_8, mix_stereo_x_to_8, mix_stereo_backwards_8, mix_stereo_backwards_16_to_8, mix_stereo_backwards_32_to_8, mix_stereo_backwards_x_to_8 }; static const void *mixer_stereo_left_16_to_8[] = { channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, channel_prepare_stereo_8_left, mix_stereo_8_left, mix_stereo_16_to_8_left, mix_stereo_32_to_8_left, mix_stereo_x_to_8_left, mix_stereo_backwards_8_left, mix_stereo_backwards_16_to_8_left, mix_stereo_backwards_32_to_8_left, mix_stereo_backwards_x_to_8_left }; static const void *mixer_stereo_right_16_to_8[] = { channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, channel_prepare_stereo_8_right, mix_stereo_8_right, mix_stereo_16_to_8_right, mix_stereo_32_to_8_right, mix_stereo_x_to_8_right, mix_stereo_backwards_8_right, mix_stereo_backwards_16_to_8_right, mix_stereo_backwards_32_to_8_right, mix_stereo_backwards_x_to_8_right }; static const void *mixer_stereo_center_16_to_8[] = { channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, channel_prepare_stereo_8_center, mix_stereo_8_center, mix_stereo_16_to_8_center, mix_stereo_32_to_8_center, diff --git a/libavsequencer/instr.c b/libavsequencer/instr.c index 3901752..935428f 100644 --- a/libavsequencer/instr.c +++ b/libavsequencer/instr.c @@ -1,621 +1,623 @@ /* * Implement AVSequencer instrument management * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Implement AVSequencer instrument management. */ #include "libavutil/log.h" #include "libavformat/avformat.h" #include "libavsequencer/avsequencer.h" static const char *instrument_name(void *p) { AVSequencerInstrument *instrument = p; AVMetadataTag *tag = av_metadata_get(instrument->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Instrument"; } static const AVClass avseq_instrument_class = { "AVSequencer Instrument", instrument_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerInstrument *avseq_instrument_create(void) { return av_mallocz(sizeof(AVSequencerInstrument) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_instrument_destroy(AVSequencerInstrument *instrument) { if (instrument) av_metadata_free(&instrument->metadata); av_free(instrument); } int avseq_instrument_open(AVSequencerModule *module, AVSequencerInstrument *instrument, uint32_t samples) { AVSequencerSample *sample; AVSequencerInstrument **instrument_list; uint32_t i; uint16_t instruments; int res; if (!module) return AVERROR_INVALIDDATA; instrument_list = module->instrument_list; instruments = module->instruments; if (!(instrument && ++instruments)) { return AVERROR_INVALIDDATA; } else if (!(instrument_list = av_realloc(instrument_list, (instruments * sizeof(AVSequencerInstrument *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate instrument storage container.\n"); return AVERROR(ENOMEM); } instrument->av_class = &avseq_instrument_class; for (i = 0; i < samples; ++i) { if (!(sample = avseq_sample_create())) { while (i--) { av_free(instrument->sample_list[i]); } av_log(instrument, AV_LOG_ERROR, "Cannot allocate sample number %d.\n", i + 1); return AVERROR(ENOMEM); } if ((res = avseq_sample_open(instrument, sample, NULL, 0)) < 0) { while (i--) { av_free(instrument->sample_list[i]); } return res; } } instrument->fade_out = 65535; instrument->pitch_pan_center = 4*12; // C-4 instrument->global_volume = 255; instrument->default_panning = -128; instrument->env_usage_flags = ~(AVSEQ_INSTRUMENT_FLAG_USE_VOLUME_ENV|AVSEQ_INSTRUMENT_FLAG_USE_PANNING_ENV|AVSEQ_INSTRUMENT_FLAG_USE_SLIDE_ENV|-0x2000); + instrument->filter_cutoff = 255; + instrument->filter_damping = 255; instrument_list[instruments - 1] = instrument; module->instrument_list = instrument_list; module->instruments = instruments; return 0; } void avseq_instrument_close(AVSequencerModule *module, AVSequencerInstrument *instrument) { AVSequencerInstrument **instrument_list; uint16_t instruments, i; if (!(module && instrument)) return; instrument_list = module->instrument_list; instruments = module->instruments; for (i = 0; i < instruments; ++i) { if (instrument_list[i] == instrument) break; } if (instruments && (i != instruments)) { AVSequencerInstrument *last_instrument = instrument_list[--instruments]; if (!instruments) { av_freep(&module->instrument_list); module->instruments = 0; } else if (!(instrument_list = av_realloc(instrument_list, (instruments * sizeof(AVSequencerInstrument *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_instruments = i + 1; instrument_list = module->instrument_list; if (copy_instruments < instruments) memmove(instrument_list + i, instrument_list + copy_instruments, (instruments - copy_instruments) * sizeof(AVSequencerInstrument *)); instrument_list[instruments - 1] = NULL; } else { const unsigned copy_instruments = i + 1; if (copy_instruments < instruments) { memmove(instrument_list + i, instrument_list + copy_instruments, (instruments - copy_instruments) * sizeof(AVSequencerInstrument *)); instrument_list[instruments - 1] = last_instrument; } module->instrument_list = instrument_list; module->instruments = instruments; } } i = instrument->samples; while (i--) { AVSequencerSample *sample = instrument->sample_list[i]; avseq_sample_close(instrument, sample); avseq_sample_destroy(sample); } } static const char *envelope_name(void *p) { AVSequencerEnvelope *envelope = p; AVMetadataTag *tag = av_metadata_get(envelope->metadata, "title", NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) return tag->value; return "AVSequencer Envelope"; } static const AVClass avseq_envelope_class = { "AVSequencer Envelope", envelope_name, NULL, LIBAVUTIL_VERSION_INT, }; AVSequencerEnvelope *avseq_envelope_create(void) { return av_mallocz(sizeof(AVSequencerEnvelope) + FF_INPUT_BUFFER_PADDING_SIZE); } void avseq_envelope_destroy(AVSequencerEnvelope *envelope) { if (envelope) av_metadata_free(&envelope->metadata); av_free(envelope); } int avseq_envelope_open(AVSequencerContext *avctx, AVSequencerModule *module, AVSequencerEnvelope *envelope, uint32_t points, uint32_t type, uint32_t scale, uint32_t y_offset, uint32_t nodes) { AVSequencerEnvelope **envelope_list; uint16_t envelopes; int res; if (!module) return AVERROR_INVALIDDATA; envelope_list = module->envelope_list; envelopes = module->envelopes; if (!(envelope && ++envelopes)) { return AVERROR_INVALIDDATA; } else if (!(envelope_list = av_realloc(envelope_list, (envelopes * sizeof(AVSequencerEnvelope *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(module, AV_LOG_ERROR, "Cannot allocate envelope storage container.\n"); return AVERROR(ENOMEM); } envelope->av_class = &avseq_envelope_class; envelope->value_min = -scale; envelope->value_max = scale; envelope->tempo = 1; if ((res = avseq_envelope_data_open(avctx, envelope, points, type, scale, y_offset, nodes)) < 0) { av_free(envelope_list); return res; } envelope_list[envelopes - 1] = envelope; module->envelope_list = envelope_list; module->envelopes = envelopes; return 0; } void avseq_envelope_close(AVSequencerModule *module, AVSequencerEnvelope *envelope) { AVSequencerEnvelope **envelope_list; uint16_t envelopes, i; if (!(module && envelope)) return; envelope_list = module->envelope_list; envelopes = module->envelopes; for (i = 0; i < envelopes; ++i) { if (envelope_list[i] == envelope) break; } if (envelopes && (i != envelopes)) { AVSequencerEnvelope *last_envelope = envelope_list[--envelopes]; uint16_t j; for (j = 0; i < module->instruments; ++j) { AVSequencerInstrument *instrument = module->instrument_list[j]; unsigned smp; if (instrument->volume_env == envelope) { if (last_envelope != envelope) instrument->volume_env = envelope_list[j + 1]; else if (i) instrument->volume_env = envelope_list[j - 1]; else instrument->volume_env = NULL; } if (instrument->panning_env == envelope) { if (last_envelope != envelope) instrument->panning_env = envelope_list[j + 1]; else if (i) instrument->panning_env = envelope_list[j - 1]; else instrument->panning_env = NULL; } if (instrument->slide_env == envelope) { if (last_envelope != envelope) instrument->slide_env = envelope_list[j + 1]; else if (i) instrument->slide_env = envelope_list[j - 1]; else instrument->slide_env = NULL; } if (instrument->vibrato_env == envelope) { if (last_envelope != envelope) instrument->vibrato_env = envelope_list[j + 1]; else if (i) instrument->vibrato_env = envelope_list[j - 1]; else instrument->vibrato_env = NULL; } if (instrument->tremolo_env == envelope) { if (last_envelope != envelope) instrument->tremolo_env = envelope_list[j + 1]; else if (i) instrument->tremolo_env = envelope_list[j - 1]; else instrument->tremolo_env = NULL; } if (instrument->pannolo_env == envelope) { if (last_envelope != envelope) instrument->pannolo_env = envelope_list[j + 1]; else if (i) instrument->pannolo_env = envelope_list[j - 1]; else instrument->pannolo_env = NULL; } if (instrument->channolo_env == envelope) { if (last_envelope != envelope) instrument->channolo_env = envelope_list[j + 1]; else if (i) instrument->channolo_env = envelope_list[j - 1]; else instrument->channolo_env = NULL; } if (instrument->spenolo_env == envelope) { if (last_envelope != envelope) instrument->spenolo_env = envelope_list[j + 1]; else if (i) instrument->spenolo_env = envelope_list[j - 1]; else instrument->spenolo_env = NULL; } for (smp = 0; smp < instrument->samples; ++smp) { AVSequencerSample *sample = instrument->sample_list[smp]; if (sample->auto_vibrato_env == envelope) { if (last_envelope != envelope) sample->auto_vibrato_env = envelope_list[i + 1]; else if (i) sample->auto_vibrato_env = envelope_list[i - 1]; else sample->auto_vibrato_env = NULL; } if (sample->auto_tremolo_env == envelope) { if (last_envelope != envelope) sample->auto_tremolo_env = envelope_list[i + 1]; else if (i) sample->auto_tremolo_env = envelope_list[i - 1]; else sample->auto_tremolo_env = NULL; } if (sample->auto_pannolo_env == envelope) { if (last_envelope != envelope) sample->auto_pannolo_env = envelope_list[i + 1]; else if (i) sample->auto_pannolo_env = envelope_list[i - 1]; else sample->auto_pannolo_env = NULL; } } } if (!envelopes) { av_freep(&module->envelope_list); module->envelopes = 0; } else if (!(envelope_list = av_realloc(envelope_list, (envelopes * sizeof(AVSequencerEnvelope *)) + FF_INPUT_BUFFER_PADDING_SIZE))) { const unsigned copy_envelopes = i + 1; envelope_list = module->envelope_list; if (copy_envelopes < envelopes) memmove(envelope_list + i, envelope_list + copy_envelopes, (envelopes - copy_envelopes) * sizeof(AVSequencerEnvelope *)); envelope_list[envelopes - 1] = NULL; } else { const unsigned copy_envelopes = i + 1; if (copy_envelopes < envelopes) { memmove(envelope_list + i, envelope_list + copy_envelopes, (envelopes - copy_envelopes) * sizeof(AVSequencerEnvelope *)); envelope_list[envelopes - 1] = last_envelope; } module->envelope_list = envelope_list; module->envelopes = envelopes; } } avseq_envelope_data_close(envelope); } #define CREATE_ENVELOPE(env_type) \ static void create_##env_type##_envelope (AVSequencerContext *avctx, \ int16_t *data, \ uint32_t points, \ uint32_t scale, \ uint32_t scale_type, \ uint32_t y_offset) CREATE_ENVELOPE(empty) { uint32_t i; for (i = points; i > 0; i--) { *data++ = y_offset; } } /** Sine table for very fast sine calculation. Value is sin(x)*32767 with one element being one degree. */ static const int16_t sine_lut[] = { 0, 571, 1143, 1714, 2285, 2855, 3425, 3993, 4560, 5125, 5689, 6252, 6812, 7370, 7927, 8480, 9031, 9580, 10125, 10667, 11206, 11742, 12274, 12803, 13327, 13847, 14364, 14875, 15383, 15885, 16383, 16876, 17363, 17846, 18323, 18794, 19259, 19719, 20173, 20620, 21062, 21497, 21925, 22347, 22761, 23169, 23570, 23964, 24350, 24729, 25100, 25464, 25820, 26168, 26509, 26841, 27165, 27480, 27787, 28086, 28377, 28658, 28931, 29195, 29450, 29696, 29934, 30162, 30381, 30590, 30790, 30981, 31163, 31335, 31497, 31650, 31793, 31927, 32050, 32164, 32269, 32363, 32448, 32522, 32587, 32642, 32687, 32722, 32747, 32762, 32767, 32762, 32747, 32722, 32687, 32642, 32587, 32522, 32448, 32363, 32269, 32164, 32050, 31927, 31793, 31650, 31497, 31335, 31163, 30981, 30790, 30590, 30381, 30162, 29934, 29696, 29450, 29195, 28931, 28658, 28377, 28086, 27787, 27480, 27165, 26841, 26509, 26168, 25820, 25464, 25100, 24729, 24350, 23964, 23570, 23169, 22761, 22347, 21925, 21497, 21062, 20620, 20173, 19719, 19259, 18794, 18323, 17846, 17363, 16876, 16383, 15885, 15383, 14875, 14364, 13847, 13327, 12803, 12274, 11742, 11206, 10667, 10125, 9580, 9031, 8480, 7927, 7370, 6812, 6252, 5689, 5125, 4560, 3993, 3425, 2855, 2285, 1714, 1143, 571, 0, -571, -1143, -1714, -2285, -2855, -3425, -3993, -4560, -5125, -5689, -6252, -6812, -7370, -7927, -8480, -9031, -9580, -10125, -10667, -11206, -11742, -12274, -12803, -13327, -13847, -14364, -14875, -15383, -15885, -16383, -16876, -17363, -17846, -18323, -18794, -19259, -19719, -20173, -20620, -21062, -21497, -21925, -22347, -22761, -23169, -23570, -23964, -24350, -24729, -25100, -25464, -25820, -26168, -26509, -26841, -27165, -27480, -27787, -28086, -28377, -28658, -28931, -29195, -29450, -29696, -29934, -30162, -30381, -30590, -30790, -30981, -31163, -31335, -31497, -31650, -31793, -31927, -32050, -32164, -32269, -32363, -32448, -32522, -32587, -32642, -32687, -32722, -32747, -32762, -32767, -32762, -32747, -32722, -32687, -32642, -32587, -32522, -32448, -32363, -32269, -32164, -32050, -31927, -31793, -31650, -31497, -31335, -31163, -30981, -30790, -30590, -30381, -30162, -29934, -29696, -29450, -29195, -28931, -28658, -28377, -28086, -27787, -27480, -27165, -26841, -26509, -26168, -25820, -25464, -25100, -24729, -24350, -23964, -23570, -23169, -22761, -22347, -21925, -21497, -21062, -20620, -20173, -19719, -19259, -18794, -18323, -17846, -17363, -16876, -16383, -15885, -15383, -14875, -14364, -13847, -13327, -12803, -12274, -11742, -11206, -10667, -10125, -9580, -9031, -8480, -7927, -7370, -6812, -6252, -5689, -5125, -4560, -3993, -3425, -2855, -2285, -1714, -1143, -571 }; CREATE_ENVELOPE(sine) { uint32_t i, sine_div, sine_mod, pos = 0, count = 0; int32_t value = 0; const int16_t *const lut = (avctx->sine_lut ? avctx->sine_lut : sine_lut); sine_div = 360 / points; sine_mod = 360 % points; for (i = points; i > 0; i--) { value = lut[pos]; if (scale_type) value = -value; pos += sine_div; value *= (int32_t) scale; value /= 32767; value += y_offset; count += sine_mod; if (count >= points) { count -= points; pos++; } *data++ = value; } } CREATE_ENVELOPE(cosine) { uint32_t i, sine_div, sine_mod, count = 0; int32_t pos = 90, value = 0; const int16_t *const lut = (avctx->sine_lut ? avctx->sine_lut : sine_lut); sine_div = 360 / points; sine_mod = 360 % points; for (i = points; i > 0; i--) { value = lut[pos]; if (scale_type) value = -value; if ((pos -= sine_div) < 0) pos += 360; value *= (int32_t) scale; value /= 32767; value += y_offset; count += sine_mod; if (count >= points) { count -= points; pos--; if (pos < 0) pos += 360; } *data++ = value; } } CREATE_ENVELOPE(ramp) { uint32_t i, start_scale = -scale, ramp_points, scale_div, scale_mod, scale_count = 0, value; if (!(ramp_points = points >> 1)) ramp_points = 1; scale_div = scale / ramp_points; scale_mod = scale % ramp_points; for (i = points; i > 0; i--) { value = start_scale; start_scale += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; start_scale++; } if (scale_type) value = -value; value += y_offset; *data++ = value; } } CREATE_ENVELOPE(square) { unsigned i; uint32_t j, value; if (scale_type) scale = -scale; for (i = 2; i > 0; i--) { scale = -scale; value = (scale + y_offset); for (j = points >> 1; j > 0; j--) { *data++ = value; } } } CREATE_ENVELOPE(triangle) { uint32_t i, value, pos = 0, down_pos, triangle_points, scale_div, scale_mod, scale_count = 0; if (!(triangle_points = points >> 2)) triangle_points = 1; scale_div = scale / triangle_points; scale_mod = scale % triangle_points; down_pos = points - triangle_points; for (i = points; i > 0; i--) { value = pos; if (down_pos >= i) { if (down_pos == i) { scale_count += scale_mod; scale_div = -scale_div; } if (triangle_points >= i) { scale_count += scale_mod; scale_div = -scale_div; down_pos = 0; } pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos--; } } else { pos += scale_div; scale_count += scale_mod; if (scale_count >= points) { scale_count -= points; pos++; } } if (scale_type) value = -value; value += y_offset; *data++ = value; } } CREATE_ENVELOPE(sawtooth) { uint32_t i, value, pos = scale, down_pos, sawtooth_points, scale_div, scale_mod, scale_count = 0; down_pos = points >> 1; if (!(sawtooth_points = points >> 2)) sawtooth_points = 1; scale_div = -(scale / sawtooth_points); scale_mod = scale % sawtooth_points; for (i = points; i > 0; i--) { diff --git a/libavsequencer/instr.h b/libavsequencer/instr.h index ecfeeed..4e28cd5 100644 --- a/libavsequencer/instr.h +++ b/libavsequencer/instr.h @@ -37,525 +37,537 @@ enum AVSequencerEnvelopeFlags { * Envelope structure used by instruments to apply volume / panning * or pitch manipulation according to an user defined waveform. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerEnvelope { /** * information on struct for av_log * - set by avseq_alloc_context */ const AVClass *av_class; /** Metadata information: Original envelope file name, envelope * name, artist and comment. */ AVMetadata *metadata; /** The actual node data of this envelope as signed 16-bit integer. For a volume envelope, we have a default scale range of -32767 to +32767, for panning envelopes the scale range is between -8191 to +8191. For slide, vibrato, tremolo, pannolo (and their auto versions), the scale range is between -256 to +256. */ int16_t *data; /** The node points values or 0 if the envelope is empty. */ uint16_t *node_points; /** Number of dragable nodes of this envelope (defaults to 12). */ uint16_t nodes; /** Number of envelope points, i.e. node data values which defaults to 64. */ uint16_t points; /** Instrument envelope flags. Some sequencers feature loop points of various kinds, which have to be taken care specially in the internal playback engine. */ uint16_t flags; /** Envelope tempo in ticks (defaults to 1, i.e. change envelope at every frame / tick). */ uint16_t tempo; /** Envelope sustain loop start point. */ uint16_t sustain_start; /** Envelope sustain loop end point. */ uint16_t sustain_end; /** Envelope sustain loop repeat counter for loop range. */ uint16_t sustain_count; /** Envelope loop repeat start point. */ uint16_t loop_start; /** Envelope loop repeat end point. */ uint16_t loop_end; /** Envelope loop repeat counter for loop range. */ uint16_t loop_count; /** Randomized lowest value allowed. */ int16_t value_min; /** Randomized highest value allowed. */ int16_t value_max; /** Array of pointers containing every unknown data field where the last element is indicated by a NULL pointer reference. The first 64-bit of the unknown data contains an unique identifier for this chunk and the second 64-bit data is actual unsigned length of the following raw data. Some formats are chunk based and can store information, which can't be handled by some other, in case of a transition the unknown data is kept as is. Some programs write editor settings for envelopes in those chunks, which then won't get lost in that case. */ uint8_t **unknown_data; } AVSequencerEnvelope; /** * Keyboard definitions structure used by instruments to map * note to samples. C-0 is first key. B-9 is 120th key. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerKeyboard { struct AVSequencerKeyboardEntry { /** Sample number for this keyboard note. */ uint16_t sample; /** Octave value for this keyboard note. */ uint8_t octave; /** Note value for this keyboard note. */ uint8_t note; } key[120]; } AVSequencerKeyboard; /** * Arpeggio data structure, This structure is actually for one tick * and therefore actually pointed as an array with the amount of * different ticks handled by the arpeggio control. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerArpeggioData { /** Packed note or 0 if this is an arpeggio note. */ uint8_t tone; /** Transpose for this arpeggio tick. */ int8_t transpose; /** Instrument number to switch to or 0 for original instrument. */ uint16_t instrument; /** The four effect command bytes which are executed. */ uint8_t command[4]; /** The four data word values of the four effect command bytes. */ uint16_t data[4]; } AVSequencerArpeggioData; /** AVSequencerArpeggio->flags bitfield. */ enum AVSequencerArpeggioFlags { AVSEQ_ARPEGGIO_FLAG_LOOP = 0x0001, ///< Arpeggio control is looped AVSEQ_ARPEGGIO_FLAG_SUSTAIN = 0x0002, ///< Arpeggio control has a sustain loop AVSEQ_ARPEGGIO_FLAG_PINGPONG = 0x0004, ///< Arpeggio control will be looped in ping pong mpde AVSEQ_ARPEGGIO_FLAG_SUSTAIN_PINGPONG = 0x0008, ///< Arpeggio control will have sustain loop ping pong mode enabled }; /** * Arpeggio control envelope used by all instrumental stuff. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerArpeggio { /** * information on struct for av_log * - set by avseq_alloc_context */ const AVClass *av_class; /** Metadata information: Original arpeggio file name, arpeggio * name, artist and comment. */ AVMetadata *metadata; /** AVSequencerArpeggioData pointer to arpeggio data structure. */ AVSequencerArpeggioData *data; /** Instrument arpeggio control flags. Some sequencers feature customized arpeggio command control, which have to be taken care specially in the internal playback engine. */ uint16_t flags; /** Number of arpeggio ticks handled by this arpeggio control (defaults to 3 points as in normal arpeggio command). */ uint16_t entries; /** Sustain loop start tick of arpeggio control. */ uint16_t sustain_start; /** Sustain loop end tick of arpeggio control. */ uint16_t sustain_end; /** Sustain loop count number of how often to repeat loop of arpeggio control. */ uint16_t sustain_count; /** Loop start tick of arpeggio control. */ uint16_t loop_start; /** Loop end tick of arpeggio control. */ uint16_t loop_end; /** Loop count number of how often to repeat loop of arpeggio control. */ uint16_t loop_count; } AVSequencerArpeggio; /** AVSequencerInstrument->nna values. */ enum AVSequencerInstrumentNNA { AVSEQ_INSTRUMENT_NNA_NOTE_CUT = 0x00, ///< Cut previous note AVSEQ_INSTRUMENT_NNA_NOTE_CONTINUE = 0x01, ///< Continue previous note AVSEQ_INSTRUMENT_NNA_NOTE_OFF = 0x02, ///< Perform key-off on previous note AVSEQ_INSTRUMENT_NNA_NOTE_FADE = 0x03, ///< Perform fadeout on previous note }; /** AVSequencerInstrument->dct values. */ enum AVSequencerInstrumentDCT { AVSEQ_INSTRUMENT_DCT_INSTR_NOTE_OR = 0x01, ///< Check for duplicate OR instrument notes AVSEQ_INSTRUMENT_DCT_SAMPLE_NOTE_OR = 0x02, ///< Check for duplicate OR sample notes AVSEQ_INSTRUMENT_DCT_INSTR_OR = 0x04, ///< Check for duplicate OR instruments AVSEQ_INSTRUMENT_DCT_SAMPLE_OR = 0x08, ///< Check for duplicate OR samples AVSEQ_INSTRUMENT_DCT_INSTR_NOTE_AND = 0x10, ///< Check for duplicate AND instrument notes AVSEQ_INSTRUMENT_DCT_SAMPLE_NOTE_AND = 0x20, ///< Check for duplicate AND sample notes AVSEQ_INSTRUMENT_DCT_INSTR_AND = 0x40, ///< Check for duplicate AND instruments AVSEQ_INSTRUMENT_DCT_SAMPLE_AND = 0x80, ///< Check for duplicate AND samples }; /** AVSequencerInstrument->dna values. */ enum AVSequencerInstrumentDNA { AVSEQ_INSTRUMENT_DNA_NOTE_CUT = 0x00, ///< Do note cut on duplicate note AVSEQ_INSTRUMENT_DNA_NOTE_OFF = 0x01, ///< Perform keyoff on duplicate note AVSEQ_INSTRUMENT_DNA_NOTE_FADE = 0x02, ///< Fade off notes on duplicate note AVSEQ_INSTRUMENT_DNA_NOTE_CONTINUE = 0x03, ///< Nothing (only useful for synth sound handling) }; /** AVSequencerInstrument->compat_flags bitfield. */ enum AVSequencerInstrumentCompatFlags { AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE = 0x01, ///< Instrument wave is locked as in MOD, but volume / panning / etc. is taken, if both bits are clear it will handle like S3M/IT, i.e. instrument is changed AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN = 0x02, ///< Instrument panning affects channel panning (IT compatibility) AVSEQ_INSTRUMENT_COMPAT_FLAG_PREV_SAMPLE = 0x04, ///< If no sample in keyboard definitions, use previous one AVSEQ_INSTRUMENT_COMPAT_FLAG_SEPARATE_SAMPLES = 0x08, ///< Use absolute instead of relative sample values (IT compatibility) }; /** AVSequencerInstrument->flags bitfield. */ enum AVSequencerInstrumentFlags { AVSEQ_INSTRUMENT_FLAG_NO_TRANSPOSE = 0x01, ///< Instrument can't be transpoed by the order list AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV = 0x02, ///< Slide envelopes will be portamento values, otherwise transpose + finetune AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV = 0x04, ///< Use linear freqency table for slide envelope for portamento mode AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING = 0x10, ///< Use instrument panning and override sample default panning AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING = 0x20, ///< Use surround sound as default instrument panning AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE = 0x40, ///< Order instrument transpose doesn't apply to this instrument }; /** AVSequencerInstrument->env_usage_flags bitfield. */ enum AVSequencerInstrumentEnvUsageFlags { AVSEQ_INSTRUMENT_FLAG_USE_VOLUME_ENV = 0x0001, ///< Use (reload) volume envelope AVSEQ_INSTRUMENT_FLAG_USE_PANNING_ENV = 0x0002, ///< Use (reload) panning envelope AVSEQ_INSTRUMENT_FLAG_USE_SLIDE_ENV = 0x0004, ///< Use (reload) slide envelope AVSEQ_INSTRUMENT_FLAG_USE_VIBRATO_ENV = 0x0008, ///< Use (reload) vibrato envelope AVSEQ_INSTRUMENT_FLAG_USE_TREMOLO_ENV = 0x0010, ///< Use (reload) tremolo envelope AVSEQ_INSTRUMENT_FLAG_USE_PANNOLO_ENV = 0x0020, ///< Use (reload) pannolo envelope AVSEQ_INSTRUMENT_FLAG_USE_CHANNOLO_ENV = 0x0040, ///< Use (reload) channolo envelope AVSEQ_INSTRUMENT_FLAG_USE_SPENOLO_ENV = 0x0080, ///< Use (reload) spenolo envelope AVSEQ_INSTRUMENT_FLAG_USE_TRACK_TREMOLO_ENV = 0x0100, ///< Use (reload) track tremolo envelope AVSEQ_INSTRUMENT_FLAG_USE_TRACK_PANNOLO_ENV = 0x0200, ///< Use (reload) track pannolo envelope AVSEQ_INSTRUMENT_FLAG_USE_GLOBAL_TREMOLO_ENV = 0x0400, ///< Use (reload) global tremolo envelope AVSEQ_INSTRUMENT_FLAG_USE_GLOBAL_PANNOLO_ENV = 0x0800, ///< Use (reload) global pannolo envelope AVSEQ_INSTRUMENT_FLAG_USE_RESONANCE_ENV = 0x1000, ///< Use (reload) resonance filter }; /** AVSequencerInstrument->env_proc_flags bitfield. */ enum AVSequencerInstrumentEnvProcFlags { AVSEQ_INSTRUMENT_FLAG_PROC_VOLUME_ENV = 0x0001, ///< Add first, then get volume envelope value AVSEQ_INSTRUMENT_FLAG_PROC_PANNING_ENV = 0x0002, ///< Add first, then get panning envelope value AVSEQ_INSTRUMENT_FLAG_PROC_SLIDE_ENV = 0x0004, ///< Add first, then get slide envelope value AVSEQ_INSTRUMENT_FLAG_PROC_VIBRATO_ENV = 0x0008, ///< Add first, then get vibrato envelope value AVSEQ_INSTRUMENT_FLAG_PROC_TREMOLO_ENV = 0x0010, ///< Add first, then get tremolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_PANNOLO_ENV = 0x0020, ///< Add first, then get pannolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_CHANNOLO_ENV = 0x0040, ///< Add first, then get channolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_SPENOLO_ENV = 0x0080, ///< Add first, then get spenolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_TRACK_TREMOLO_ENV = 0x0100, ///< Add first, then get track tremolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_TRACK_PANNOLO_ENV = 0x0200, ///< Add first, then get track pannolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_GLOBAL_TREMOLO_ENV = 0x0400, ///< Add first, then get global tremolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_GLOBAL_PANNOLO_ENV = 0x0800, ///< Add first, then get global pannolo envelope value AVSEQ_INSTRUMENT_FLAG_PROC_RESONANCE_ENV = 0x1000, ///< Add first, then get resonance filter value }; /** AVSequencerInstrument->env_retrig_flags bitfield. */ enum AVSequencerInstrumentEnvRetrigFlags { AVSEQ_INSTRUMENT_FLAG_RETRIG_VOLUME_ENV = 0x0001, ///< Not retrigger volume envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_PANNING_ENV = 0x0002, ///< Not retrigger panning envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_SLIDE_ENV = 0x0004, ///< Not retrigger slide envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_VIBRATO_ENV = 0x0008, ///< Not retrigger vibrato envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_TREMOLO_ENV = 0x0010, ///< Not retrigger tremolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_PANNOLO_ENV = 0x0020, ///< Not retrigger pannolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_CHANNOLO_ENV = 0x0040, ///< Not retrigger channolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_SPENOLO_ENV = 0x0080, ///< Not retrigger spenolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_TRACK_TREMOLO_ENV = 0x0100, ///< Not retrigger track tremolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_TRACK_PANNOLO_ENV = 0x0200, ///< Not retrigger track pannolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_GLOBAL_TREMOLO_ENV = 0x0400, ///< Not retrigger global tremolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_GLOBAL_PANNOLO_ENV = 0x0800, ///< Not retrigger global pannolo envelope AVSEQ_INSTRUMENT_FLAG_RETRIG_RESONANCE_ENV = 0x1000, ///< Not retrigger resonance filter }; /** AVSequencerInstrument->env_random_flags bitfield. */ enum AVSequencerInstrumentEnvRandomFlags { AVSEQ_INSTRUMENT_FLAG_RANDOM_VOLUME_ENV = 0x0001, ///< Randomize volume envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_PANNING_ENV = 0x0002, ///< Randomize panning envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_SLIDE_ENV = 0x0004, ///< Randomize slide envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_VIBRATO_ENV = 0x0008, ///< Randomize vibrato envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_TREMOLO_ENV = 0x0010, ///< Randomize tremolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_PANNOLO_ENV = 0x0020, ///< Randomize pannolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_CHANNOLO_ENV = 0x0040, ///< Randomize channolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_SPENOLO_ENV = 0x0080, ///< Randomize spenolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_TRACK_TREMOLO_ENV = 0x0100, ///< Randomize track tremolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_TRACK_PANNOLO_ENV = 0x0200, ///< Randomize track pannolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_GLOBAL_TREMOLO_ENV = 0x0400, ///< Randomize global tremolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_GLOBAL_PANNOLO_ENV = 0x0800, ///< Randomize global pannolo envelope AVSEQ_INSTRUMENT_FLAG_RANDOM_RESONANCE_ENV = 0x1000, ///< Randomize resonance filter }; /** AVSequencerInstrument->env_rnd_delay_flags bitfield. */ enum AVSequencerInstrumentEnvRndDelayFlags { AVSEQ_INSTRUMENT_FLAG_RND_DELAY_VOLUME_ENV = 0x0001, ///< Speed is randomized delay for volume envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_PANNING_ENV = 0x0002, ///< Speed is randomized delay for panning envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_SLIDE_ENV = 0x0004, ///< Speed is randomized delay for slide envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_VIBRATO_ENV = 0x0008, ///< Speed is randomized delay for vibrato envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_TREMOLO_ENV = 0x0010, ///< Speed is randomized delay for tremolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_PANNOLO_ENV = 0x0020, ///< Speed is randomized delay for pannolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_CHANNOLO_ENV = 0x0040, ///< Speed is randomized delay for channolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_SPENOLO_ENV = 0x0080, ///< Speed is randomized delay for spenolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_TRACK_TREMOLO_ENV = 0x0100, ///< Speed is randomized delay for track tremolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_TRACK_PANNOLO_ENV = 0x0200, ///< Speed is randomized delay for track pannolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_GLOBAL_TREMOLO_ENV = 0x0400, ///< Speed is randomized delay for global tremolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_GLOBAL_PANNOLO_ENV = 0x0800, ///< Speed is randomized delay for global pannolo envelope AVSEQ_INSTRUMENT_FLAG_RND_DELAY_RESONANCE_ENV = 0x1000, ///< Speed is randomized delay for resonance filter }; /** AVSequencerInstrument->midi_flags bitfield. */ enum AVSequencerInstrumentMIDIFlags { AVSEQ_INSTRUMENT_FLAG_MIDI_TICK_QUANTIZE = 0x01, ///< Tick quantize (insert note delays) AVSEQ_INSTRUMENT_FLAG_MIDI_NOTE_OFF = 0x02, ///< Record note off (keyoff note) AVSEQ_INSTRUMENT_FLAG_MIDI_VELOCITY = 0x04, ///< Record velocity AVSEQ_INSTRUMENT_FLAG_MIDI_AFTER_TOUCH = 0x08, ///< Record after touch AVSEQ_INSTRUMENT_FLAG_MIDI_EXTERNAL_SYNC = 0x10, ///< External synchronization when recording AVSEQ_INSTRUMENT_FLAG_MIDI_ENABLE = 0x80, ///< MIDI enabled }; #include "libavsequencer/sample.h" /** * Instrument structure used by all instrumental stuff. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. */ typedef struct AVSequencerInstrument { /** * information on struct for av_log * - set by avseq_alloc_context */ const AVClass *av_class; /** Metadata information: Original instrument file name, instrument * name, artist and comment. */ AVMetadata *metadata; /** Array (of size samples) of pointers containing every sample used by this instrument. */ AVSequencerSample **sample_list; /** Number of samples associated with this instrument (a maximum number of 255 attached samples is allowed). The default is one attached sample. */ uint8_t samples; /** Pointer to envelope data interpreted as volume control or NULL if volume envelope control is not used. */ AVSequencerEnvelope *volume_env; /** Pointer to envelope data interpreted as panning control or NULL if panning envelope control is not used. */ AVSequencerEnvelope *panning_env; /** Pointer to envelope data interpreted as pitch and slide control or NULL if slide envelope control is not used. */ AVSequencerEnvelope *slide_env; /** Pointer to envelope data interpreted as vibrato waveform control or NULL if vibrato envelope is not used. */ AVSequencerEnvelope *vibrato_env; /** Pointer to envelope data interpreted as tremolo waveform control or NULL if tremolo envelope is not used. */ AVSequencerEnvelope *tremolo_env; /** Pointer to envelope data interpreted as pannolo / panbrello waveform control or NULL if pannolo envelope is not used. */ AVSequencerEnvelope *pannolo_env; /** Pointer to envelope data interpreted as channolo waveform control or NULL if channolo envelope is not used. */ AVSequencerEnvelope *channolo_env; /** Pointer to envelope data interpreted as spenolo waveform control or NULL if spenolo envelope is not used. */ AVSequencerEnvelope *spenolo_env; /** Pointer to envelope data interpreted as resonance filter control or NULL if resonance filter is unused. */ AVSequencerEnvelope *resonance_env; /** Pointer to arpeggio control structure to be used for custom apreggios or NULL if this instrument uses standard arpeggio behaviour. */ AVSequencerArpeggio *arpeggio_ctrl; /** Pointer to instrument keyboard definitions which maps the octave/instrument-pair to an associated sample. */ AVSequencerKeyboard *keyboard_defs; /** Global volume scaling instrument samples. */ uint8_t global_volume; /** NNA (New Note Action) mode. */ uint8_t nna; /** Random note swing in semi-tones. This value will cause a flip between each play of this instrument making it sounding more natural. */ uint8_t note_swing; /** Random volume swing in 1/256th steps (i.e. 256 means 100%). The volume will vibrate randomnessly around that volume percentage and make the instrument sound more like a natural playing. */ uint16_t volume_swing; /** Random panning swing, will cause the stereo position to vary a bit each instrument play to make it sound more naturally played. */ uint16_t panning_swing; /** Random pitch swing in 1/65536th steps, i.e. 65536 means 100%. */ uint32_t pitch_swing; /** Pitch panning separation. */ int16_t pitch_pan_separation; /** Default panning for all samples. */ uint8_t default_panning; /** Default sub-panning for all samples. */ uint8_t default_sub_pan; /** Duplicate note check type. */ uint8_t dct; /** Duplicate note check action. */ uint8_t dna; /** Compatibility flags for playback. There are rare cases where instrument to sample mapping has to be handled a different way, or a different policy for no sample specified cases. */ uint8_t compat_flags; /** Instrument playback flags. Some sequencers feature surround panning or allow different types of envelope interpretations, differend types of slides which have to be taken care specially in the internal playback engine. */ uint8_t flags; /** Envelope usage flags. Some sequencers feature reloading of envelope data when a new note is played. */ uint16_t env_usage_flags; /** Envelope processing flags. Some sequencers differ in the way how they handle envelopes. Some first increment envelope node and then get the data and some do first get the data and then increment the envelope data. */ uint16_t env_proc_flags; /** Envelope retrigger flags. Some sequencers differ in the way how they handle envelopes restart. Some continue the previous instrument envelope when an new instrument does not define an envelope, others disable this envelope instead. */ uint16_t env_retrig_flags; /** Envelope randomize flags. Some sequencers allow to use data from a pseudo random number generator. If the approciate bit is set, the envelope data will be randomized each access. */ uint16_t env_random_flags; /** Envelope randomize delay flags. Some sequencers allow to specify a time interval when a new random value can be read. */ uint16_t env_rnd_delay_flags; /** Fade out value which defaults to 65535 (full volume level as in XM). */ uint16_t fade_out; /** Hold value. */ uint16_t hold; /** Decay value. */ uint16_t decay; /** Decay action when decay is off. */ uint8_t dca; /** Pitch panning center (0 is C-0, 1 is C#1, 12 is C-1, 13 is C#1, 24 is C-2, 36 is C-3 and so on. Defaults to 48 = C-4). */ uint8_t pitch_pan_center; /** MIDI channel this instrument is associated with. */ uint8_t midi_channel; /** MIDI program (instrument) this instrument maps to. */ uint8_t midi_program; /** MIDI flags. Some sequencers allow general MIDI support and can play certain instruments directly through a MIDI channel. */ uint8_t midi_flags; /** MIDI transpose (in half-tones). */ int8_t midi_transpose; /** MIDI after touch percentage. */ uint8_t midi_after_touch; /** MIDI pitch bender (in half-tones). */ uint8_t midi_pitch_bender; + /** Default (resonance) filter cutoff for this channel which + ranges from 0 to 127. Natural frequency is calculated by + nat_freq = 2*PI*110*(2^0.25)*2^(filter_cutoff/24). If set to + 255, the default (resonance) filter cutoff is not applied. */ + uint8_t filter_cutoff; + + /** Default (resonance) filter damping for this channel which + ranges from 0 to 127. Damping factor is calculated by + damp_factor = 10^(-((24/128)*filter_damping)/20). If set to + 255, the default (resonance) filter damping is not applied. */ + uint8_t filter_damping; + /** Array of pointers containing every unknown data field where the last element is indicated by a NULL pointer reference. The first 64-bit of the unknown data contains an unique identifier for this chunk and the second 64-bit data is actual unsigned length of the following raw data. Some formats are chunk based and can store information, which can't be handled by some other, in case of a transition the unknown data is kept as is. Some programs write editor settings for instruments in those chunks, which then won't get lost in that case. */ uint8_t **unknown_data; } AVSequencerInstrument; #endif /* AVSEQUENCER_INSTR_H */ diff --git a/libavsequencer/player.c b/libavsequencer/player.c index bd5c68d..78bf853 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -263,1025 +263,1025 @@ USE_ENVELOPE(track_tremolo) return &player_host_channel->track_trem_env; } USE_ENVELOPE(track_pannolo) { return &player_host_channel->track_pan_env; } USE_ENVELOPE(global_tremolo) { return &avctx->player_globals->tremolo_env; } USE_ENVELOPE(global_pannolo) { return &avctx->player_globals->pannolo_env; } USE_ENVELOPE(arpeggio) { return &player_host_channel->arpepggio_env; } USE_ENVELOPE(resonance) { return &player_channel->resonance_env; } #define PRESET_EFFECT(fx_type) \ static void preset_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t data_word) PRESET_EFFECT(tone_portamento) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA; } PRESET_EFFECT(vibrato) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO; } PRESET_EFFECT(note_delay) { if ((player_host_channel->note_delay = data_word)) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = player_host_channel->note_delay; } } } PRESET_EFFECT(tremolo) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO; } PRESET_EFFECT(set_transpose) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE; player_host_channel->transpose = data_word >> 8; player_host_channel->trans_finetune = data_word; } static const int32_t portamento_mask[8] = { 0, 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE }; static const int32_t portamento_trigger_mask[6] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN }; #define CHECK_EFFECT(fx_type) \ static void check_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t *const fx_byte, \ uint16_t *const data_word, \ uint16_t *const flags) CHECK_EFFECT(portamento) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE); player_host_channel->fine_slide_flags |= portamento_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { if ((*fx_byte <= AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN) && !(player_host_channel->fine_slide_flags & (AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE))) goto trigger_portamento_done; *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE) *fx_byte += AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES) && (*fx_byte > AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; *fx_byte &= -2; if (player_host_channel->fine_slide_flags & portamento_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN - 1)]) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; } trigger_portamento_done: *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(tone_portamento) { } CHECK_EFFECT(note_slide) { uint8_t note_slide_type; if (!(note_slide_type = (*data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; if (note_slide_type & 0xF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE }; static const int32_t volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN }; CHECK_EFFECT(volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE); player_host_channel->fine_slide_flags |= volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; *fx_byte &= -2; if (volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(volume_slide_to) { if ((*data_word >> 8) == 0xFF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t track_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE }; static const int32_t track_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN }; CHECK_EFFECT(track_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE); player_host_channel->fine_slide_flags |= track_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; *fx_byte &= -2; if (track_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE }; static const int32_t panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT }; CHECK_EFFECT(panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE); player_host_channel->fine_slide_flags |= panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; *fx_byte &= -2; if (panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t track_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE }; static const int32_t track_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT }; CHECK_EFFECT(track_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE); player_host_channel->fine_slide_flags |= track_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; *fx_byte &= -2; if (track_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t speed_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE }; static const int32_t speed_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER }; CHECK_EFFECT(speed_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE); player_host_channel->fine_slide_flags |= speed_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; *fx_byte &= -2; if (speed_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(channel_control) { } static const int32_t global_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE }; static const int32_t global_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN }; CHECK_EFFECT(global_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE); player_host_channel->fine_slide_flags |= global_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t global_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE }; static const int32_t global_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT }; CHECK_EFFECT(global_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE); player_host_channel->fine_slide_flags |= global_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static int16_t step_envelope(AVSequencerContext *const avctx, AVSequencerPlayerEnvelope *const player_envelope, const int16_t *const envelope_data, uint16_t envelope_pos, const uint16_t tempo_multiplier, const int16_t value_adjustment) { uint32_t seed, randomize_value; const uint16_t envelope_restart = player_envelope->start; int16_t value; value = envelope_data[envelope_pos]; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM) { avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; - randomize_value = (player_envelope->value_max - player_envelope->value_min) + 1; + randomize_value = ((int32_t) player_envelope->value_max - (int32_t) player_envelope->value_min) + 1; value = ((uint64_t) seed * randomize_value) >> 32; value += player_envelope->value_min; } value += value_adjustment; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS) { if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over_back; for (;;) { check_back_envelope_loop: if (envelope_pos <= envelope_restart) break; loop_envelope_over_back: if (envelope_restart == player_envelope->end) goto run_envelope_check_pingpong_wait; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + envelope_restart; if (envelope_pos < envelope_restart) goto check_envelope_loop; goto loop_envelope_over; } else { envelope_pos += player_envelope->end - envelope_restart; } } } else { if (envelope_pos < tempo_multiplier) player_envelope->tempo = 0; envelope_pos -= tempo_multiplier; } } else if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over; for (;;) { check_envelope_loop: if (envelope_pos <= player_envelope->end) break; loop_envelope_over: if (envelope_restart == player_envelope->end) { run_envelope_check_pingpong_wait: envelope_pos = envelope_restart; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; break; } if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + player_envelope->end; if (envelope_pos < player_envelope->end) goto check_back_envelope_loop; goto loop_envelope_over_back; } else { envelope_pos += envelope_restart - player_envelope->end; } } } else { envelope_pos += tempo_multiplier; if ((envelope_pos < tempo_multiplier) || (envelope_pos > player_envelope->end)) player_envelope->tempo = 0; } player_envelope->pos = envelope_pos; if ((player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD) && !(player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM)) value = envelope_data[envelope_pos] + value_adjustment; return value; } static void set_envelope(AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope *const envelope, uint16_t envelope_pos) { const AVSequencerEnvelope *instrument_envelope; uint8_t envelope_flags; uint16_t envelope_loop_start, envelope_loop_end; if (!(instrument_envelope = envelope->envelope)) return; envelope_flags = AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING; envelope_loop_start = envelope->loop_start; envelope_loop_end = envelope->loop_end; if ((envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_SUSTAIN) && !(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN)) { envelope_loop_start = envelope->sustain_start; envelope_loop_end = envelope->sustain_end; } else if (!(envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_LOOP)) { envelope_flags = 0; envelope_loop_end = instrument_envelope->points - 1; } if (envelope_loop_start > envelope_loop_end) envelope_loop_start = envelope_loop_end; if (envelope_pos > envelope_loop_end) envelope_pos = envelope_loop_end; envelope->pos = envelope_pos; envelope->start = envelope_loop_start; envelope->end = envelope_loop_end; envelope->flags = envelope_flags; } static int16_t run_envelope(AVSequencerContext *const avctx, AVSequencerPlayerEnvelope *const player_envelope, uint16_t tempo_multiplier, int16_t value_adjustment) { const AVSequencerEnvelope *envelope; int16_t value = player_envelope->value; if ((envelope = player_envelope->envelope)) { const int16_t *envelope_data = envelope->data; const uint16_t envelope_pos = player_envelope->pos; if (player_envelope->tempo) { uint16_t envelope_count; if (!(envelope_count = player_envelope->tempo_count)) player_envelope->value = value = step_envelope(avctx, player_envelope, envelope_data, envelope_pos, tempo_multiplier, value_adjustment); player_envelope->tempo_count = ++envelope_count; if ((player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM) && (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY)) tempo_multiplier *= player_envelope->tempo; else tempo_multiplier = player_envelope->tempo; if (envelope_count >= tempo_multiplier) player_envelope->tempo_count = 0; else if ((player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD) && !(player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM)) value = envelope_data[envelope_pos] + value_adjustment; } } return value; } static void play_key_off(AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *sample; const AVSequencerSynthWave *waveform; uint32_t repeat, repeat_length, repeat_count; uint8_t flags; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN) return; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN; set_envelope(player_channel, &player_channel->vol_env, player_channel->vol_env.pos); set_envelope(player_channel, &player_channel->pan_env, player_channel->pan_env.pos); set_envelope(player_channel, &player_channel->slide_env, player_channel->slide_env.pos); set_envelope(player_channel, &player_channel->auto_vib_env, player_channel->auto_vib_env.pos); set_envelope(player_channel, &player_channel->auto_trem_env, player_channel->auto_trem_env.pos); set_envelope(player_channel, &player_channel->auto_pan_env, player_channel->auto_pan_env.pos); set_envelope(player_channel, &player_channel->resonance_env, player_channel->resonance_env.pos); if ((!player_channel->vol_env.envelope) || (!player_channel->vol_env.tempo) || (player_channel->vol_env.flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING)) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; if ((sample = player_channel->sample) && (sample->flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP)) { repeat = sample->repeat; repeat_length = sample->rep_len; repeat_count = sample->rep_count; player_channel->mixer.repeat_start = repeat; player_channel->mixer.repeat_length = repeat_length; player_channel->mixer.repeat_count = repeat_count; flags = player_channel->mixer.flags & ~(AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG|AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS); if ((sample->flags & AVSEQ_SAMPLE_FLAG_LOOP) && repeat_length) { flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (sample->repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (sample->repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = flags; } if ((waveform = player_channel->sample_waveform) && (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_SUSTAIN_LOOP)) { repeat = waveform->repeat; repeat_length = waveform->rep_len; repeat_count = waveform->rep_count; player_channel->mixer.repeat_start = repeat; player_channel->mixer.repeat_length = repeat_length; player_channel->mixer.repeat_count = repeat_count; flags = player_channel->mixer.flags & ~(AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG|AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS); if (!(waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_NOLOOP) && repeat_length) { flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (waveform->repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_PINGPONG) flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (waveform->repeat_mode & AVSEQ_SYNTH_WAVE_REP_MODE_BACKWARDS) flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = flags; } if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_VOLUME) player_channel->entry_pos[0] = player_channel->sustain_pos[0]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_PANNING) player_channel->entry_pos[1] = player_channel->sustain_pos[1]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SLIDE) player_channel->entry_pos[2] = player_channel->sustain_pos[2]; if (player_channel->use_sustain_flags & AVSEQ_PLAYER_CHANNEL_USE_SUSTAIN_FLAG_SPECIAL) player_channel->entry_pos[3] = player_channel->sustain_pos[3]; } /** Linear frequency table. Value is 65536*2^(x/3072). */ static const uint16_t linear_frequency_lut[] = { 0, 15, 30, 44, 59, 74, 89, 104, 118, 133, 148, 163, 178, 193, 207, 222, 237, 252, 267, 282, 296, 311, 326, 341, 356, 371, 386, 400, 415, 430, 445, 460, 475, 490, 505, 520, 535, 549, 564, 579, 594, 609, 624, 639, 654, 669, 684, 699, 714, 729, 744, 758, 773, 788, 803, 818, 833, 848, 863, 878, 893, 908, 923, 938, 953, 968, 983, 998, 1013, 1028, 1043, 1058, 1073, 1088, 1103, 1118, 1134, 1149, 1164, 1179, 1194, 1209, 1224, 1239, 1254, 1269, 1284, 1299, 1314, 1329, 1344, 1360, 1375, 1390, 1405, 1420, 1435, 1450, 1465, 1480, 1496, 1511, 1526, 1541, 1556, 1571, 1586, 1601, 1617, 1632, 1647, 1662, 1677, 1692, 1708, 1723, 1738, 1753, 1768, 1784, 1799, 1814, 1829, 1844, 1859, 1875, 1890, 1905, 1920, 1936, 1951, 1966, 1981, 1996, 2012, 2027, 2042, 2057, 2073, 2088, 2103, 2119, 2134, 2149, 2164, 2180, 2195, 2210, 2225, 2241, 2256, 2271, 2287, 2302, 2317, 2333, 2348, 2363, 2379, 2394, 2409, 2425, 2440, 2455, 2471, 2486, 2501, 2517, 2532, 2547, 2563, 2578, 2593, 2609, 2624, 2640, 2655, 2670, 2686, 2701, 2716, 2732, 2747, 2763, 2778, 2794, 2809, 2824, 2840, 2855, 2871, 2886, 2902, 2917, 2932, 2948, 2963, 2979, 2994, 3010, 3025, 3041, 3056, 3072, 3087, 3103, 3118, 3134, 3149, 3165, 3180, 3196, 3211, 3227, 3242, 3258, 3273, 3289, 3304, 3320, 3335, 3351, 3366, 3382, 3397, 3413, 3429, 3444, 3460, 3475, 3491, 3506, 3522, 3538, 3553, 3569, 3584, 3600, 3616, 3631, 3647, 3662, 3678, 3694, 3709, 3725, 3740, 3756, 3772, 3787, 3803, 3819, 3834, 3850, 3866, 3881, 3897, 3913, 3928, 3944, 3960, 3975, 3991, 4007, 4022, 4038, 4054, 4070, 4085, 4101, 4117, 4132, 4148, 4164, 4180, 4195, 4211, 4227, 4242, 4258, 4274, 4290, 4305, 4321, 4337, 4353, 4369, 4384, 4400, 4416, 4432, 4447, 4463, 4479, 4495, 4511, 4526, 4542, 4558, 4574, 4590, 4606, 4621, 4637, 4653, 4669, 4685, 4701, 4716, 4732, 4748, 4764, 4780, 4796, 4812, 4827, 4843, 4859, 4875, 4891, 4907, 4923, 4939, 4955, 4971, 4986, 5002, 5018, 5034, 5050, 5066, 5082, 5098, 5114, 5130, 5146, 5162, 5178, 5194, 5210, 5226, 5241, 5257, 5273, 5289, 5305, 5321, 5337, 5353, 5369, 5385, 5401, 5417, 5433, 5449, 5465, 5481, 5497, 5513, 5530, 5546, 5562, 5578, 5594, 5610, 5626, 5642, 5658, 5674, 5690, 5706, 5722, 5738, 5754, 5770, 5787, 5803, 5819, 5835, 5851, 5867, 5883, 5899, 5915, 5932, 5948, 5964, 5980, 5996, 6012, 6028, 6044, 6061, 6077, 6093, 6109, 6125, 6141, 6158, 6174, 6190, 6206, 6222, 6239, 6255, 6271, 6287, 6303, 6320, 6336, 6352, 6368, 6384, 6401, 6417, 6433, 6449, 6466, 6482, 6498, 6514, 6531, 6547, 6563, 6579, 6596, 6612, 6628, 6645, 6661, 6677, 6693, 6710, 6726, 6742, 6759, 6775, 6791, 6808, 6824, 6840, 6857, 6873, 6889, 6906, 6922, 6938, 6955, 6971, 6987, 7004, 7020, 7037, 7053, 7069, 7086, 7102, 7118, 7135, 7151, 7168, 7184, 7200, 7217, 7233, 7250, 7266, 7283, 7299, 7315, 7332, 7348, 7365, 7381, 7398, 7414, 7431, 7447, 7463, 7480, 7496, 7513, 7529, 7546, 7562, 7579, 7595, 7612, 7628, 7645, 7661, 7678, 7694, 7711, 7728, 7744, 7761, 7777, 7794, 7810, 7827, 7843, 7860, 7876, 7893, 7910, 7926, 7943, 7959, 7976, 7992, 8009, 8026, 8042, 8059, 8075, 8092, 8109, 8125, 8142, 8159, 8175, 8192, 8208, 8225, 8242, 8258, 8275, 8292, 8308, 8325, 8342, 8358, 8375, 8392, 8408, 8425, 8442, 8458, 8475, 8492, 8509, 8525, 8542, 8559, 8575, 8592, 8609, 8626, 8642, 8659, 8676, 8693, 8709, 8726, 8743, 8760, 8776, 8793, 8810, 8827, 8843, 8860, 8877, 8894, 8911, 8927, 8944, 8961, 8978, 8995, 9012, 9028, 9045, 9062, 9079, 9096, 9112, 9129, 9146, 9163, 9180, 9197, 9214, 9230, 9247, 9264, 9281, 9298, 9315, 9332, 9349, 9366, 9382, 9399, 9416, 9433, 9450, 9467, 9484, 9501, 9518, 9535, 9552, 9569, 9586, 9603, 9620, 9636, 9653, 9670, 9687, 9704, 9721, 9738, 9755, 9772, 9789, 9806, 9823, 9840, 9857, 9874, 9891, 9908, 9925, 9942, 9959, 9976, 9993, 10011, 10028, 10045, 10062, 10079, 10096, 10113, 10130, 10147, 10164, 10181, 10198, 10215, 10232, 10250, 10267, 10284, 10301, 10318, 10335, 10352, 10369, 10386, 10404, 10421, 10438, 10455, 10472, 10489, 10506, 10524, 10541, 10558, 10575, 10592, 10610, 10627, 10644, 10661, 10678, 10695, 10713, 10730, 10747, 10764, 10782, 10799, 10816, 10833, 10850, 10868, 10885, 10902, 10919, 10937, 10954, 10971, 10988, 11006, 11023, 11040, 11058, 11075, 11092, 11109, 11127, 11144, 11161, 11179, 11196, 11213, 11231, 11248, 11265, 11283, 11300, 11317, 11335, 11352, 11369, 11387, 11404, 11421, 11439, 11456, 11473, 11491, 11508, 11526, 11543, 11560, 11578, 11595, 11613, 11630, 11647, 11665, 11682, 11700, 11717, 11735, 11752, 11769, 11787, 11804, 11822, 11839, 11857, 11874, 11892, 11909, 11927, 11944, 11961, 11979, 11996, 12014, 12031, 12049, 12066, 12084, 12102, 12119, 12137, 12154, 12172, 12189, 12207, 12224, 12242, 12259, 12277, 12294, 12312, 12330, 12347, 12365, 12382, 12400, 12417, 12435, 12453, 12470, 12488, 12505, 12523, 12541, 12558, 12576, 12594, 12611, 12629, 12646, 12664, 12682, 12699, 12717, 12735, 12752, 12770, 12788, 12805, 12823, 12841, 12858, 12876, 12894, 12912, 12929, 12947, 12965, 12982, 13000, 13018, 13036, 13053, 13071, 13089, 13106, 13124, 13142, 13160, 13177, 13195, 13213, 13231, 13249, 13266, 13284, 13302, 13320, 13337, 13355, 13373, 13391, 13409, 13427, 13444, 13462, 13480, 13498, 13516, 13533, 13551, 13569, 13587, 13605, 13623, 13641, 13658, 13676, 13694, 13712, 13730, 13748, 13766, 13784, 13802, 13819, 13837, 13855, 13873, 13891, 13909, 13927, 13945, 13963, 13981, 13999, 14017, 14035, 14053, 14071, 14088, 14106, 14124, 14142, 14160, 14178, 14196, 14214, 14232, 14250, 14268, 14286, 14304, 14322, 14340, 14358, 14376, 14394, 14413, 14431, 14449, 14467, 14485, 14503, 14521, 14539, 14557, 14575, 14593, 14611, 14629, 14647, 14665, 14684, 14702, 14720, 14738, 14756, 14774, 14792, 14810, 14829, 14847, 14865, 14883, 14901, 14919, 14937, 14956, 14974, 14992, 15010, 15028, 15046, 15065, 15083, 15101, 15119, 15137, 15156, 15174, 15192, 15210, 15228, 15247, 15265, 15283, 15301, 15320, 15338, 15356, 15374, 15393, 15411, 15429, 15447, 15466, 15484, 15502, 15521, 15539, 15557, 15575, 15594, 15612, 15630, 15649, 15667, 15685, 15704, 15722, 15740, 15759, 15777, 15795, 15814, 15832, 15850, 15869, 15887, 15906, 15924, 15942, 15961, 15979, 15997, 16016, 16034, 16053, 16071, 16089, 16108, 16126, 16145, 16163, 16182, 16200, 16218, 16237, 16255, 16274, 16292, 16311, 16329, 16348, 16366, 16385, 16403, 16422, 16440, 16459, 16477, 16496, 16514, 16533, 16551, 16570, 16588, 16607, 16625, 16644, 16662, 16681, 16700, 16718, 16737, 16755, 16774, 16792, 16811, 16830, 16848, 16867, 16885, 16904, 16922, 16941, 16960, 16978, 16997, 17016, 17034, 17053, 17071, 17090, 17109, 17127, 17146, 17165, 17183, 17202, 17221, 17239, 17258, 17277, 17295, 17314, 17333, 17352, 17370, 17389, 17408, 17426, 17445, 17464, 17483, 17501, 17520, 17539, 17557, 17576, 17595, 17614, 17633, 17651, 17670, 17689, 17708, 17726, 17745, 17764, 17783, 17802, 17820, 17839, 17858, 17877, 17896, 17914, 17933, 17952, 17971, 17990, 18009, 18028, 18046, 18065, 18084, 18103, 18122, 18141, 18160, 18179, 18197, 18216, 18235, 18254, 18273, 18292, 18311, 18330, 18349, 18368, 18387, 18405, 18424, 18443, 18462, 18481, 18500, 18519, 18538, 18557, 18576, 18595, 18614, 18633, 18652, 18671, 18690, 18709, 18728, 18747, 18766, 18785, 18804, 18823, 18842, 18861, 18880, 18899, 18918, 18937, 18957, 18976, 18995, 19014, 19033, 19052, 19071, 19090, 19109, 19128, 19147, 19167, 19186, 19205, 19224, 19243, 19262, 19281, 19300, 19320, 19339, 19358, 19377, 19396, 19415, 19435, 19454, 19473, 19492, 19511, 19530, 19550, 19569, 19588, 19607, 19626, 19646, 19665, 19684, 19703, 19723, 19742, 19761, 19780, 19800, 19819, 19838, 19857, 19877, 19896, 19915, 19934, 19954, 19973, 19992, 20012, 20031, 20050, 20070, 20089, 20108, 20128, 20147, 20166, 20186, 20205, 20224, 20244, 20263, 20282, 20302, 20321, 20340, 20360, 20379, 20399, 20418, 20437, 20457, 20476, 20496, 20515, 20534, 20554, 20573, 20593, 20612, 20632, 20651, 20670, 20690, 20709, 20729, 20748, 20768, 20787, 20807, 20826, 20846, 20865, 20885, 20904, 20924, 20943, 20963, 20982, 21002, 21021, 21041, 21060, 21080, 21099, 21119, 21139, 21158, 21178, 21197, 21217, 21236, 21256, 21276, 21295, 21315, 21334, 21354, 21374, 21393, 21413, 21432, 21452, 21472, 21491, 21511, 21531, 21550, 21570, 21589, 21609, 21629, 21648, 21668, 21688, 21708, 21727, 21747, 21767, 21786, 21806, 21826, 21845, 21865, 21885, 21905, 21924, 21944, 21964, 21984, 22003, 22023, 22043, 22063, 22082, 22102, 22122, 22142, 22161, 22181, 22201, 22221, 22241, 22260, 22280, 22300, 22320, 22340, 22360, 22379, 22399, 22419, 22439, 22459, 22479, 22498, 22518, 22538, 22558, 22578, 22598, 22618, 22638, 22658, 22677, 22697, 22717, 22737, 22757, 22777, 22797, 22817, 22837, 22857, 22877, 22897, 22917, 22937, 22957, 22977, 22996, 23016, 23036, 23056, 23076, 23096, 23116, 23136, 23156, 23176, 23196, 23216, 23237, 23257, 23277, 23297, 23317, 23337, 23357, 23377, 23397, 23417, 23437, 23457, 23477, 23497, 23517, 23537, 23558, 23578, 23598, 23618, 23638, 23658, 23678, 23698, 23719, 23739, 23759, 23779, 23799, 23819, 23839, 23860, 23880, 23900, 23920, 23940, 23961, 23981, 24001, 24021, 24041, 24062, 24082, 24102, 24122, 24142, 24163, 24183, 24203, 24223, 24244, 24264, 24284, 24304, 24325, 24345, 24365, 24386, 24406, 24426, 24446, 24467, 24487, 24507, 24528, 24548, 24568, 24589, 24609, 24629, 24650, 24670, 24690, 24711, 24731, 24752, 24772, 24792, 24813, 24833, 24853, 24874, 24894, 24915, 24935, 24956, 24976, 24996, 25017, 25037, 25058, 25078, 25099, 25119, 25139, 25160, 25180, 25201, 25221, 25242, 25262, 25283, 25303, 25324, 25344, 25365, 25385, 25406, 25426, 25447, 25467, 25488, 25508, 25529, 25550, 25570, 25591, 25611, 25632, 25652, 25673, 25694, 25714, 25735, 25755, 25776, 25797, 25817, 25838, 25858, 25879, 25900, 25920, 25941, 25962, 25982, 26003, 26023, 26044, 26065, 26085, 26106, 26127, 26148, 26168, 26189, 26210, 26230, 26251, 26272, 26292, 26313, 26334, 26355, 26375, 26396, 26417, 26438, 26458, 26479, 26500, 26521, 26541, 26562, 26583, 26604, 26625, 26645, 26666, 26687, 26708, 26729, 26749, 26770, 26791, 26812, 26833, 26854, 26874, 26895, 26916, 26937, 26958, 26979, 27000, 27021, 27041, 27062, 27083, 27104, 27125, 27146, 27167, 27188, 27209, 27230, 27251, 27271, 27292, 27313, 27334, 27355, 27376, 27397, 27418, 27439, 27460, 27481, 27502, 27523, 27544, 27565, 27586, 27607, 27628, 27649, 27670, 27691, 27712, 27733, 27754, 27775, 27796, 27818, 27839, 27860, 27881, 27902, 27923, 27944, 27965, 27986, 28007, 28028, 28049, 28071, 28092, 28113, 28134, 28155, 28176, 28197, 28219, 28240, 28261, 28282, 28303, 28324, 28346, 28367, 28388, 28409, 28430, 28452, 28473, 28494, 28515, 28536, 28558, 28579, 28600, 28621, 28643, 28664, 28685, 28706, 28728, 28749, 28770, 28791, 28813, 28834, 28855, 28877, 28898, 28919, 28941, 28962, 28983, 29005, 29026, 29047, 29069, 29090, 29111, 29133, 29154, 29175, 29197, 29218, 29240, 29261, 29282, 29304, 29325, 29346, 29368, 29389, 29411, 29432, 29454, 29475, 29496, 29518, 29539, 29561, 29582, 29604, 29625, 29647, 29668, 29690, 29711, 29733, 29754, 29776, 29797, 29819, 29840, 29862, 29883, 29905, 29926, 29948, 29969, 29991, 30012, 30034, 30056, 30077, 30099, 30120, 30142, 30164, 30185, 30207, 30228, 30250, 30272, 30293, 30315, 30336, 30358, 30380, 30401, 30423, 30445, 30466, 30488, 30510, 30531, 30553, 30575, 30596, 30618, 30640, 30661, 30683, 30705, 30727, 30748, 30770, 30792, 30814, 30835, 30857, 30879, 30900, 30922, 30944, 30966, 30988, 31009, 31031, 31053, 31075, 31097, 31118, 31140, 31162, 31184, 31206, 31227, 31249, 31271, 31293, 31315, 31337, 31359, 31380, 31402, 31424, 31446, 31468, 31490, 31512, 31534, 31555, 31577, 31599, 31621, 31643, 31665, 31687, 31709, 31731, 31753, 31775, 31797, 31819, 31841, 31863, 31885, 31907, 31929, 31951, 31973, 31995, 32017, 32039, 32061, 32083, 32105, 32127, 32149, 32171, 32193, 32215, 32237, 32259, 32281, 32303, 32325, 32347, 32369, 32392, 32414, 32436, 32458, 32480, 32502, 32524, 32546, 32568, 32591, 32613, 32635, 32657, 32679, 32701, 32724, 32746, 32768, 32790, 32812, 32834, 32857, 32879, 32901, 32923, 32945, 32968, 32990, 33012, 33034, 33057, 33079, 33101, 33123, 33146, 33168, 33190, 33213, 33235, 33257, 33279, 33302, 33324, 33346, 33369, 33391, 33413, 33436, 33458, 33480, 33503, 33525, 33547, 33570, 33592, 33614, 33637, 33659, 33682, 33704, 33726, 33749, 33771, 33794, 33816, 33838, 33861, 33883, 33906, 33928, 33951, 33973, 33995, 34018, 34040, 34063, 34085, 34108, 34130, 34153, 34175, 34198, 34220, 34243, 34265, 34288, 34310, 34333, 34355, 34378, 34400, 34423, 34446, 34468, 34491, 34513, 34536, 34558, 34581, 34604, 34626, 34649, 34671, 34694, 34717, 34739, 34762, 34785, 34807, 34830, 34852, 34875, 34898, 34920, 34943, 34966, 34988, 35011, 35034, 35057, 35079, 35102, 35125, 35147, 35170, 35193, 35216, 35238, 35261, 35284, 35307, 35329, 35352, 35375, 35398, 35420, 35443, 35466, 35489, 35512, 35534, 35557, 35580, 35603, 35626, 35648, 35671, 35694, 35717, 35740, 35763, 35785, 35808, 35831, 35854, 35877, 35900, 35923, 35946, 35969, 35991, 36014, 36037, 36060, 36083, 36106, 36129, 36152, 36175, 36198, 36221, 36244, 36267, 36290, 36313, 36336, 36359, 36382, 36405, 36428, 36451, 36474, 36497, 36520, 36543, 36566, 36589, 36612, 36635, 36658, 36681, 36704, 36727, 36750, 36773, 36796, 36820, 36843, 36866, 36889, 36912, 36935, 36958, 36981, 37004, 37028, 37051, 37074, 37097, 37120, 37143, 37167, 37190, 37213, 37236, 37259, 37282, 37306, 37329, 37352, 37375, 37399, 37422, 37445, 37468, 37491, 37515, 37538, 37561, 37584, 37608, 37631, 37654, 37678, 37701, 37724, 37747, 37771, 37794, 37817, 37841, 37864, 37887, 37911, 37934, 37957, 37981, 38004, 38028, 38051, 38074, 38098, 38121, 38144, 38168, 38191, 38215, 38238, 38261, 38285, 38308, 38332, 38355, 38379, 38402, 38426, 38449, 38472, 38496, 38519, 38543, 38566, 38590, 38613, 38637, 38660, 38684, 38707, 38731, 38754, 38778, 38802, 38825, 38849, 38872, 38896, 38919, 38943, 38966, 38990, 39014, 39037, 39061, 39084, 39108, 39132, 39155, 39179, 39202, 39226, 39250, 39273, 39297, 39321, 39344, 39368, 39392, 39415, 39439, 39463, 39486, 39510, 39534, 39558, 39581, 39605, 39629, 39652, 39676, 39700, 39724, 39747, 39771, 39795, 39819, 39843, 39866, 39890, 39914, 39938, 39961, 39985, 40009, 40033, 40057, 40081, 40104, 40128, 40152, 40176, 40200, 40224, 40248, 40271, 40295, 40319, 40343, 40367, 40391, 40415, 40439, 40463, 40486, 40510, 40534, 40558, 40582, 40606, 40630, 40654, 40678, 40702, 40726, 40750, 40774, 40798, 40822, 40846, 40870, 40894, 40918, 40942, 40966, 40990, 41014, 41038, 41062, 41086, 41110, 41134, 41158, 41182, 41207, 41231, 41255, 41279, 41303, 41327, 41351, 41375, 41399, 41424, 41448, 41472, 41496, 41520, 41544, 41568, 41593, 41617, 41641, 41665, 41689, 41714, 41738, 41762, 41786, 41810, 41835, 41859, 41883, 41907, 41932, 41956, 41980, 42004, 42029, 42053, 42077, 42101, 42126, 42150, 42174, 42199, 42223, 42247, 42272, 42296, 42320, 42345, 42369, 42393, 42418, 42442, 42466, 42491, 42515, 42539, 42564, 42588, 42613, 42637, 42661, 42686, 42710, 42735, 42759, 42784, 42808, 42833, 42857, 42881, 42906, 42930, 42955, 42979, 43004, 43028, 43053, 43077, 43102, 43126, 43151, 43175, 43200, 43224, 43249, 43274, 43298, 43323, 43347, 43372, 43396, 43421, 43446, 43470, 43495, 43519, 43544, 43569, 43593, 43618, 43642, 43667, 43692, 43716, 43741, 43766, 43790, 43815, 43840, 43864, 43889, 43914, 43938, 43963, 43988, 44013, 44037, 44062, 44087, 44111, 44136, 44161, 44186, 44210, 44235, 44260, 44285, 44310, 44334, 44359, 44384, 44409, 44434, 44458, 44483, 44508, 44533, 44558, 44583, 44607, 44632, 44657, 44682, 44707, 44732, 44757, 44781, 44806, 44831, 44856, 44881, 44906, 44931, 44956, 44981, 45006, 45031, 45056, 45081, 45106, 45131, 45155, 45180, 45205, 45230, 45255, 45280, 45305, 45330, 45355, 45381, 45406, 45431, 45456, 45481, 45506, 45531, 45556, 45581, 45606, 45631, 45656, 45681, 45706, 45731, 45757, 45782, 45807, 45832, 45857, 45882, 45907, 45932, 45958, 45983, 46008, 46033, 46058, 46083, 46109, 46134, 46159, 46184, 46209, 46235, 46260, 46285, 46310, 46336, 46361, 46386, 46411, 46437, 46462, 46487, 46512, 46538, 46563, 46588, 46614, 46639, 46664, 46690, 46715, 46740, 46766, 46791, 46816, 46842, 46867, 46892, 46918, 46943, 46968, 46994, 47019, 47045, 47070, 47095, 47121, 47146, 47172, 47197, 47223, 47248, 47273, 47299, 47324, 47350, 47375, 47401, 47426, 47452, 47477, 47503, 47528, 47554, 47579, 47605, 47630, 47656, 47681, 47707, 47733, 47758, 47784, 47809, 47835, 47860, 47886, 47912, 47937, 47963, 47988, 48014, 48040, 48065, 48091, 48117, 48142, 48168, 48194, 48219, 48245, 48271, 48296, 48322, 48348, 48373, 48399, 48425, 48450, 48476, 48502, 48528, 48553, 48579, 48605, 48631, 48656, 48682, 48708, 48734, 48759, 48785, 48811, 48837, 48863, 48888, 48914, 48940, 48966, 48992, 49018, 49044, 49069, 49095, 49121, 49147, 49173, 49199, 49225, 49251, 49276, 49302, 49328, 49354, 49380, 49406, 49432, 49458, 49484, 49510, 49536, 49562, 49588, 49614, 49640, 49666, 49692, 49718, 49744, 49770, 49796, 49822, 49848, 49874, 49900, 49926, 49952, 49978, 50004, 50030, 50056, 50082, 50108, 50135, 50161, 50187, 50213, 50239, 50265, 50291, 50317, 50343, 50370, 50396, 50422, 50448, 50474, 50500, 50527, 50553, 50579, 50605, 50631, 50658, 50684, 50710, 50736, 50763, 50789, 50815, 50841, 50868, 50894, 50920, 50946, 50973, 50999, 51025, 51052, 51078, 51104, 51131, 51157, 51183, 51210, 51236, 51262, 51289, 51315, 51341, 51368, 51394, 51420, 51447, 51473, 51500, 51526, 51552, 51579, 51605, 51632, 51658, 51685, 51711, 51738, 51764, 51790, 51817, 51843, 51870, 51896, 51923, 51949, 51976, 52002, 52029, 52056, 52082, 52109, 52135, 52162, 52188, 52215, 52241, 52268, 52295, 52321, 52348, 52374, 52401, 52428, 52454, 52481, 52507, 52534, 52561, 52587, 52614, 52641, 52667, 52694, 52721, 52747, 52774, 52801, 52827, 52854, 52881, 52908, 52934, 52961, 52988, 53015, 53041, 53068, 53095, 53122, 53148, 53175, 53202, 53229, 53256, 53282, 53309, 53336, 53363, 53390, 53416, 53443, 53470, 53497, 53524, 53551, 53578, 53605, 53631, 53658, 53685, 53712, 53739, 53766, 53793, 53820, 53847, 53874, 53901, 53928, 53955, 53981, 54008, 54035, 54062, 54089, 54116, 54143, 54170, 54197, 54224, 54251, 54278, 54306, 54333, 54360, 54387, 54414, 54441, 54468, 54495, 54522, 54549, 54576, 54603, 54630, 54658, 54685, 54712, 54739, 54766, 54793, 54820, 54848, 54875, 54902, 54929, 54956, 54983, 55011, 55038, 55065, 55092, 55119, 55147, 55174, 55201, 55228, 55256, 55283, 55310, 55337, 55365, 55392, 55419, 55447, 55474, 55501, 55529, 55556, 55583, 55611, 55638, 55665, 55693, 55720, 55747, 55775, 55802, 55829, 55857, 55884, 55912, 55939, 55966, 55994, 56021, 56049, 56076, 56104, 56131, 56158, 56186, 56213, 56241, 56268, 56296, 56323, 56351, 56378, 56406, 56433, 56461, 56488, 56516, 56543, 56571, 56599, 56626, 56654, 56681, 56709, 56736, 56764, 56792, 56819, 56847, 56874, 56902, 56930, 56957, 56985, 57013, 57040, 57068, 57096, 57123, 57151, 57179, 57206, 57234, 57262, 57289, 57317, 57345, 57373, 57400, 57428, 57456, 57484, 57511, 57539, 57567, 57595, 57622, 57650, 57678, 57706, 57734, 57761, 57789, 57817, 57845, 57873, 57901, 57929, 57956, 57984, 58012, 58040, 58068, 58096, 58124, 58152, 58179, 58207, 58235, 58263, 58291, 58319, 58347, 58375, 58403, 58431, 58459, 58487, 58515, 58543, 58571, 58599, 58627, 58655, 58683, 58711, 58739, 58767, 58795, 58823, 58851, 58879, 58907, 58935, 58964, 58992, 59020, 59048, 59076, 59104, 59132, 59160, 59189, 59217, 59245, 59273, 59301, 59329, 59357, 59386, 59414, 59442, 59470, 59498, 59527, 59555, 59583, 59611, 59640, 59668, 59696, 59724, 59753, 59781, 59809, 59837, 59866, 59894, 59922, 59951, 59979, 60007, 60036, 60064, 60092, 60121, 60149, 60177, 60206, 60234, 60263, 60291, 60319, 60348, 60376, 60405, 60433, 60461, 60490, 60518, 60547, 60575, 60604, 60632, 60661, 60689, 60717, 60746, 60774, 60803, 60831, 60860, 60889, 60917, 60946, 60974, 61003, 61031, 61060, 61088, 61117, 61146, 61174, 61203, 61231, 61260, 61289, 61317, 61346, 61374, 61403, 61432, 61460, 61489, 61518, 61546, 61575, 61604, 61632, 61661, 61690, 61718, 61747, 61776, 61805, 61833, 61862, 61891, 61920, 61948, 61977, 62006, 62035, 62063, 62092, 62121, 62150, 62179, 62208, 62236, 62265, 62294, 62323, 62352, 62381, 62409, 62438, 62467, 62496, 62525, 62554, 62583, 62612, 62641, 62670, 62698, 62727, 62756, 62785, 62814, 62843, 62872, 62901, 62930, 62959, 62988, 63017, 63046, 63075, 63104, 63133, 63162, 63191, 63220, 63249, 63278, 63308, 63337, 63366, 63395, 63424, 63453, 63482, 63511, 63540, 63569, 63599, 63628, 63657, 63686, 63715, 63744, 63774, 63803, 63832, 63861, 63890, 63919, 63949, 63978, 64007, 64036, 64066, 64095, 64124, 64153, 64183, 64212, 64241, 64270, 64300, 64329, 64358, 64388, 64417, 64446, 64476, 64505, 64534, 64564, 64593, 64622, 64652, 64681, 64711, 64740, 64769, 64799, 64828, 64858, 64887, 64916, 64946, 64975, 65005, 65034, 65064, 65093, 65123, 65152, 65182, 65211, 65241, 65270, 65300, 65329, 65359, 65388, 65418, 65447, 65477, 65506, 0 }; static uint32_t linear_slide_up(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { const uint32_t linear_slide_div = slide_value / 3072; const uint32_t linear_slide_mod = slide_value % 3072; const uint32_t linear_multiplier = (0x10000 + (avctx->linear_frequency_lut ? avctx->linear_frequency_lut[linear_slide_mod] : linear_frequency_lut[linear_slide_mod])) << linear_slide_div; uint64_t slide_frequency = ((uint64_t) linear_multiplier * frequency) >> 16; if (slide_frequency > 0xFFFFFFFF) slide_frequency = -1; return (player_channel->frequency = slide_frequency); } static uint32_t amiga_slide_up(AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { uint32_t period = AVSEQ_SLIDE_CONST / frequency; if (period <= slide_value) return 1; period -= slide_value; return (player_channel->frequency = (AVSEQ_SLIDE_CONST / period)); } static uint32_t linear_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { const uint32_t linear_slide_div = slide_value / 3072; const uint32_t linear_slide_mod = slide_value % 3072; uint32_t linear_multiplier = 0x10000; if (!linear_slide_mod) linear_multiplier <<= 1; linear_multiplier += (avctx->linear_frequency_lut ? avctx->linear_frequency_lut[-linear_slide_mod + 3072] : linear_frequency_lut[-linear_slide_mod + 3072]); return (player_channel->frequency = ((uint64_t) linear_multiplier * frequency) >> (17 + linear_slide_div)); } static uint32_t amiga_slide_down(AVSequencerPlayerChannel *const player_channel, const uint32_t frequency, const uint32_t slide_value) { uint32_t period = AVSEQ_SLIDE_CONST / frequency; uint32_t new_frequency; period += slide_value; if (period < slide_value) return 0; new_frequency = AVSEQ_SLIDE_CONST / period; if (frequency == new_frequency) { if (!new_frequency--) new_frequency = 0; } return (player_channel->frequency = new_frequency); } /** Note frequency lookup table. Value is 65536*2^(x/12). */ static const uint32_t pitch_lut[] = { 0x0000F1A2, // B-3 0x00010000, // C-4 0x00010F39, // C#4 0x00011F5A, // D-4 0x00013070, // D#4 0x0001428A, // E-4 0x000155B8, // F-4 0x00016A0A, // F#4 0x00017F91, // G-4 0x00019660, // G#4 0x0001AE8A, // A-4 0x0001C824, // A#4 0x0001E343, // B-4 0x00020000 // C-5 }; static uint32_t get_tone_pitch(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, int16_t note) { const AVSequencerSample *const sample = player_host_channel->sample; const uint32_t *frequency_lut;
BastyCDGS/ffmpeg-soc
01bf26a3664d62ad2b8ba13f6bdd691ec76867d7
Fixed permissions and backwards looping in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index e28ab0c..9b68f9a 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -832,1281 +832,1281 @@ static void get_backwards_next_sample_x_to_8(struct AV_HQMixerChannelInfo *const channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const struct ChannelBlock *const channel_next_block = &channel_info->next; const uint32_t count_restart = channel_info->current.count_restart; const uint32_t counted = channel_info->current.counted + 1; if (count_restart && (count_restart == counted)) { if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } else { offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; div_volume = channel_next_block->div_volume; offset = channel_next_block->offset; } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - while ((int32_t) offset <= ((int32_t) end_offset)) { + while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; smp = smp_value + interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; int32_t interpolate_frac = ~curr_frac >> 8; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += 0x1000000; interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += 0x1000000; interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac >> 8; interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); *mix_buf++ += ((int64_t) interpolate_div << 32) / interpolate_frac; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; smp = smp_value + interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; int32_t interpolate_frac = ~curr_frac >> 8; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_frac += 0x1000000; interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_frac += 0x1000000; interpolate_div += get_sample_func(channel_info, channel_block, curr_offset) >> 8; curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset); interpolate_frac += curr_frac >> 8; interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); *mix_buf += ((int64_t) interpolate_div << 32) / interpolate_frac; mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; diff --git a/libavsequencer/instr.h b/libavsequencer/instr.h old mode 100755 new mode 100644 diff --git a/libavsequencer/module.h b/libavsequencer/module.h old mode 100755 new mode 100644 diff --git a/libavsequencer/sample.h b/libavsequencer/sample.h old mode 100755 new mode 100644 diff --git a/libavsequencer/song.h b/libavsequencer/song.h old mode 100755 new mode 100644 diff --git a/libavsequencer/synth.h b/libavsequencer/synth.h old mode 100755 new mode 100644 diff --git a/libavsequencer/track.h b/libavsequencer/track.h old mode 100755 new mode 100644
BastyCDGS/ffmpeg-soc
468d49c38417ed62dc4a76cbf5f05f1b32cd96c1
Fixed interpolation taking account of counted looping in high quality mixer and some small nits as well as partial tremolo and pannolo effect fixing.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index 7d54cad..1112c91 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1,1910 +1,2112 @@ /* * Sequencer high quality integer mixer * Copyright (c) 2011 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer high quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_HQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_HQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_HQMixerData; typedef struct AV_HQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t div_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint8_t filter_cutoff; uint8_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; int32_t prev_sample; int32_t curr_sample; int32_t next_sample; int32_t prev_sample_r; int32_t curr_sample_r; int32_t next_sample_r; int mix_right; } AV_HQMixerChannelInfo; #if CONFIG_HIGH_QUALITY_MIXER static const char *high_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_high_quality_mixer_class = { "AVSequencer High Quality Mixer", high_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_HQMixerChannelInfo *channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; int32_t c1 = channel_block->filter_c1; int32_t c2 = channel_block->filter_c2; int32_t c3 = channel_block->filter_c3; int32_t o1 = channel_info->filter_tmp2; int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; - uint32_t counted; - uint32_t count_restart; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - counted = channel_info->current.counted++; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted++; - if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { + if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - counted = channel_info->current.counted++; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted++; - if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { + if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } #define MIX(type) \ static void mix_##type(const AV_HQMixerData *const mixer_data, \ struct AV_HQMixerChannelInfo *const channel_info, \ struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } static void get_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int8_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset + 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int8_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int8_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset - 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int16_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint16_t) sample[offset + 1] >> 8]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int16_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint16_t) sample[offset - 1] >> 8]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint32_t) sample[offset + 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint32_t) sample[offset - 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int16_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int16_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset -= channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset -= channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - struct ChannelBlock *channel_next_block = &channel_info->next; - - offset += channel_block->restart_offset; + const struct ChannelBlock *const channel_next_block = &channel_info->next; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted + 1; + + if (count_restart && (count_restart == counted)) { + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } else if (channel_info->mix_right) { + channel_info->next_sample_r = 0; + } else { + channel_info->next_sample = 0; + } + } else { + offset += channel_block->restart_offset; - if (channel_next_block->data) { - sample = (const int32_t *) channel_next_block->data; - mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; - div_volume = channel_next_block->div_volume; - offset += channel_next_block->offset; + if (channel_next_block->data) { + sample = (const int32_t *) channel_next_block->data; + mult_volume = channel_info->mix_right ? channel_next_block->mult_right_volume : channel_next_block->mult_left_volume; + div_volume = channel_next_block->div_volume; + offset = channel_next_block->offset; + } } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; - while (offset < end_offset) { + while ((int32_t) offset <= ((int32_t) end_offset)) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; smp = smp_value + interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const adv_frac), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; int32_t interpolate_frac = ~curr_frac >> 8; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_div += get_sample_func(channel_info, channel_block, curr_offset, &interpolate_frac) >> 8; curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_div += get_sample_func(channel_info, channel_block, curr_offset, &interpolate_frac) >> 8; curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset, NULL); interpolate_frac += curr_frac >> 8; interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); *mix_buf++ += ((int64_t) interpolate_div << 32) / interpolate_frac; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_16_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_32_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x_to_8) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_x_to_8; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_16) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_16; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16; channel_info->curr_sample = get_curr_sample_16(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_32) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_32; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32; channel_info->curr_sample = get_curr_sample_32(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(mono_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(mono_backwards_x) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_x; mix_average_mono(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x; channel_info->curr_sample = get_curr_sample_x(channel_info, channel_block, *offset); mix_mono_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } static void mix_left_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; smp = smp_value + interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf += smp; mix_buf += 2; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_left(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const adv_frac), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; do { int32_t smp = get_curr_sample_func(channel_info, channel_block, curr_offset); int32_t interpolate_div = ((int64_t) (~curr_frac >> 1) * smp) >> 39; int32_t interpolate_frac = ~curr_frac >> 8; uint32_t interpolate_count = advance - 1; curr_offset += offset_inc; while (interpolate_count--) { interpolate_div += get_sample_func(channel_info, channel_block, curr_offset, &interpolate_frac) >> 8; curr_offset += offset_inc; } curr_frac += adv_frac; if (curr_frac < adv_frac) { interpolate_div += get_sample_func(channel_info, channel_block, curr_offset, &interpolate_frac) >> 8; curr_offset += offset_inc; } smp = get_sample_func(channel_info, channel_block, curr_offset, NULL); interpolate_frac += curr_frac >> 8; interpolate_div += (((int64_t) (curr_frac >> 1) * smp) >> 39); *mix_buf += ((int64_t) interpolate_div << 32) / interpolate_frac; mix_buf += 2; } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } MIX(stereo_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_8; channel_info->curr_sample = get_curr_sample_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_16_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_16_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_16_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_16_to_8; channel_info->curr_sample = get_curr_sample_16_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_32_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_32_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_32_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_32_to_8; channel_info->curr_sample = get_curr_sample_32_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, 1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, 1, offset, fraction, advance, adv_frac, len); } } MIX(stereo_backwards_x_to_8_left) { if (advance) { int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) = get_curr_sample_x_to_8; int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) = get_backwards_sample_1_x_to_8; mix_average_left(mixer_data, channel_info, channel_block, buf, get_curr_sample_func, get_sample_func, -1, offset, fraction, advance, adv_frac, len); } else { void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) = get_backwards_next_sample_x_to_8; channel_info->curr_sample = get_curr_sample_x_to_8(channel_info, channel_block, *offset); mix_left_loop(mixer_data, channel_info, channel_block, buf, get_next_sample_func, -1, offset, fraction, advance, adv_frac, len); } } diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 1d42a46..142b281 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -1,824 +1,824 @@ /* * Sequencer low quality integer mixer * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer low quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_LQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_LQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_LQMixerData; typedef struct AV_LQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t div_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint8_t filter_cutoff; uint8_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; } AV_LQMixerChannelInfo; #if CONFIG_LOW_QUALITY_MIXER static const char *low_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_low_quality_mixer_class = { "AVSequencer Low Quality Mixer", low_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_LQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; int32_t c1 = channel_block->filter_c1; int32_t c2 = channel_block->filter_c2; int32_t c3 = channel_block->filter_c3; int32_t o1 = channel_info->filter_tmp2; int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_LQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_LQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; - uint32_t counted; - uint32_t count_restart; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - counted = channel_info->current.counted++; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted++; - if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { + if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { - counted = channel_info->current.counted++; + const uint32_t count_restart = channel_info->current.count_restart; + const uint32_t counted = channel_info->current.counted++; - if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { + if (count_restart && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_LQMixerData *const mixer_data, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } #define MIX_FUNCTION(INIT, TYPE, OP1, OP2, OFFSET_START, OFFSET_END, \ SKIP, NEXTS, NEXTA, SHIFTS, SHIFTN, SHIFTB) \ const TYPE *sample = (const TYPE *) channel_block->data; \ int32_t *mix_buf = *buf; \ uint32_t curr_offset = *offset; \ uint32_t curr_frac = *fraction; \ uint32_t i; \ INIT; \ \ if (advance) { \ if (mixer_data->interpolation) { \ int32_t smp; \ int32_t interpolate_div; \ \ OFFSET_START; \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_advance_interpolated_sample; \ \ i--; \ \ do { \ uint32_t interpolate_offset = advance; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) \ interpolate_offset++; \ \ smp = 0; \ interpolate_div = 0; \ \ do { \ NEXTA; \ interpolate_div++; \ } while (--interpolate_offset); \ \ smp /= interpolate_div; \ SHIFTS; \ get_second_advance_interpolated_sample: \ interpolate_offset = advance; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) \ interpolate_offset++; \ \ smp = 0; \ interpolate_div = 0; \ \ do { \ NEXTA; \ interpolate_div++; \ } while (--interpolate_offset); \ \ smp /= interpolate_div; \ SHIFTS; \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } else { \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_advance_sample; \ \ i--; \ \ do { \ SKIP; \ curr_frac += adv_frac; \ curr_offset OP1 advance; \ \ if (curr_frac < adv_frac) \ curr_offset OP2; \ get_second_advance_sample: \ SKIP; \ curr_frac += adv_frac; \ curr_offset OP1 advance; \ \ if (curr_frac < adv_frac) \ curr_offset OP2; \ } while (--i); \ \ *buf = mix_buf; \ *offset = curr_offset; \ *fraction = curr_frac; \ } \ } else { \ int32_t smp; \ \ if (mixer_data->interpolation > 1) { \ uint32_t interpolate_frac, interpolate_count; \ int32_t interpolate_div; \ int64_t smp_value; \ \ OFFSET_START; \ NEXTS; \ smp_value = 0; \ \ if (len) \ smp_value = (*sample - smp) * (int64_t) adv_frac; \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_interpolated_sample; \ \ i--; \ \ do { \ SHIFTS; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ NEXTS; \ smp_value = 0; \ \ if (len) \ smp_value = (*sample - smp) * (int64_t) adv_frac; \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ } else { \ smp += interpolate_div; \ interpolate_count += interpolate_frac; \ \ if (interpolate_count < interpolate_frac) { \ smp++; \ \ if (interpolate_div < 0) \ smp -= 2; \ } \ } \ get_second_interpolated_sample: \ SHIFTS; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ NEXTS; \ smp_value = 0; \ \ if (len) \ smp_value = (*sample - smp) * (int64_t) adv_frac; \ \ interpolate_div = smp_value >> 32; \ interpolate_frac = smp_value; \ interpolate_count = 0; \ } else { \ smp += interpolate_div; \ interpolate_count += interpolate_frac; \ \ if (interpolate_count < interpolate_frac) { \ smp++; \ \ if (interpolate_div < 0) \ smp -= 2; \ } \ } \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } else { \ OFFSET_START; \ SHIFTN; \ i = (len >> 1) + 1; \ \ if (len & 1) \ goto get_second_sample; \ \ i--; \ \ do { \ SHIFTB; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ SHIFTN; \ } \ get_second_sample: \ SHIFTB; \ curr_frac += adv_frac; \ \ if (curr_frac < adv_frac) { \ SHIFTN; \ } \ } while (--i); \ \ *buf = mix_buf; \ OFFSET_END; \ *fraction = curr_frac; \ } \ } #define MIX(type) \ static void mix_##type(const AV_LQMixerData *const mixer_data, \ const struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } MIX(mono_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *sample++, smp += *sample++, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *sample++], *mix_buf++ += smp) } MIX(mono_backwards_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int8_t *const pos = sample, int8_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint8_t) sample[curr_offset]], smp = *--sample, smp += *--sample, *mix_buf++ += volume_lut[(uint8_t) smp], smp = volume_lut[(uint8_t) *--sample], *mix_buf++ += smp) } MIX(mono_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *sample++, smp += *sample++, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *sample++ >> 8], *mix_buf++ += smp) } MIX(mono_backwards_16_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int16_t *const pos = sample, int16_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint16_t) sample[curr_offset] >> 8], smp = *--sample, smp += *--sample, *mix_buf++ += volume_lut[(uint16_t) smp >> 8], smp = volume_lut[(uint16_t) *--sample >> 8], *mix_buf++ += smp) } MIX(mono_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, +=, ++, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *sample++, smp += *sample++, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *sample++ >> 24], *mix_buf++ += smp) } MIX(mono_backwards_32_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const int32_t *const pos = sample, int32_t, -=, --, sample += curr_offset, *offset = (sample - pos) - 1, *mix_buf++ += volume_lut[(uint32_t) sample[curr_offset] >> 24], smp = *--sample, smp += *--sample, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], smp = volume_lut[(uint32_t) *--sample >> 24], *mix_buf++ += smp) } MIX(mono_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, +=, ++, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = smp_data, if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp += smp_data, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample++ << bit; smp_data |= ((uint32_t) *sample & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } bit += bits_per_sample; curr_offset++; smp = volume_lut[(uint32_t) smp_data >> 24], *mix_buf++ += smp) } MIX(mono_backwards_x_to_8) { MIX_FUNCTION(const int32_t *const volume_lut = channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit = curr_offset * bits_per_sample; uint32_t smp_offset = bit >> 5; uint32_t smp_data, int32_t, -=, --, sample += smp_offset, *offset = curr_offset, bit = curr_offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } *mix_buf++ += volume_lut[(uint32_t) smp_data >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = smp_data, curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp += smp_data, *mix_buf++ += volume_lut[(uint32_t) smp >> 24], curr_offset--; bit -= bits_per_sample; if ((int32_t) bit < 0) { sample--; bit &= 31; } if ((bit + bits_per_sample) < 32) { smp_data = ((uint32_t) *sample << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) *sample << bit; smp_data |= ((uint32_t) *(sample+1) & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 30a3e9e..52e3b7b 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -2633,1701 +2633,1701 @@ EXECUTE_EFFECT(tone_portamento_once) player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = data_word; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(note_slide) { uint16_t note_slide_value, note_slide_type; if (!(note_slide_value = (uint8_t) data_word)) note_slide_value = player_host_channel->note_slide; player_host_channel->note_slide = note_slide_value; if (!(note_slide_type = (data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; player_host_channel->note_slide_type = note_slide_type; if (!(note_slide_type & 0x10)) note_slide_value = -note_slide_value; note_slide_value += player_host_channel->final_note; player_host_channel->final_note = note_slide_value; if (player_channel->host_channel == channel) player_channel->frequency = get_tone_pitch(avctx, player_host_channel, player_channel, note_slide_value); } EXECUTE_EFFECT(vibrato) { uint16_t vibrato_rate; int16_t vibrato_depth; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; vibrato_depth = (int8_t) data_word; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, vibrato_depth << 2); } EXECUTE_EFFECT(fine_vibrato) { uint16_t vibrato_rate; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, (int8_t) data_word); } EXECUTE_EFFECT(do_key_off) { if (data_word <= player_host_channel->tempo_counter) play_key_off(player_channel); } EXECUTE_EFFECT(hold_delay) { // TODO: Implement hold delay effect } EXECUTE_EFFECT(note_fade) { if (data_word <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } EXECUTE_EFFECT(note_cut) { if ((data_word & 0xFFF) <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) { player_channel->volume = 0; player_channel->sub_volume = 0; if (data_word & 0xF000) { player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_channel->mixer.flags = 0; } } } } EXECUTE_EFFECT(note_delay) { } EXECUTE_EFFECT(tremor) { uint8_t tremor_off, tremor_on; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; if (!(tremor_off = (uint8_t) data_word)) tremor_off = player_host_channel->tremor_off_ticks; player_host_channel->tremor_off_ticks = tremor_off; if (!(tremor_on = (data_word >> 8))) tremor_on = player_host_channel->tremor_on_ticks; player_host_channel->tremor_on_ticks = tremor_on; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF)) tremor_off = tremor_on; if (tremor_off <= player_host_channel->tremor_count) { player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF; player_host_channel->tremor_count = 0; } player_host_channel->tremor_count++; } EXECUTE_EFFECT(note_retrigger) { uint16_t retrigger_tick = data_word & 0x7FFF, retrigger_tick_count; if ((data_word & 0x8000) && data_word) retrigger_tick = player_host_channel->tempo / retrigger_tick; if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --retrigger_tick) { if (retrigger_tick <= retrigger_tick_count) retrigger_tick_count = -1; } else if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; } player_host_channel->retrig_tick_count = ++retrigger_tick_count; } EXECUTE_EFFECT(multi_retrigger_note) { uint8_t multi_retrigger_tick, multi_retrigger_volume_change; uint16_t retrigger_tick_count; uint32_t volume; if (!(multi_retrigger_tick = (data_word >> 8))) multi_retrigger_tick = player_host_channel->multi_retrig_tick; player_host_channel->multi_retrig_tick = multi_retrigger_tick; if (!(multi_retrigger_volume_change = (uint8_t) data_word)) multi_retrigger_volume_change = player_host_channel->multi_retrig_vol_chg; player_host_channel->multi_retrig_vol_chg = multi_retrigger_volume_change; if ((retrigger_tick_count = player_host_channel->retrig_tick_count) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE) || (player_channel->host_channel != channel)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; } else if ((int8_t) multi_retrigger_volume_change < 0) { uint8_t multi_retrigger_scale = 4; if (!(avctx->player_song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES)) multi_retrigger_scale = player_host_channel->multi_retrig_scale; if ((int8_t) (multi_retrigger_volume_change -= 0xBF) >= 0) { volume = multi_retrigger_volume_change * multi_retrigger_scale; if (player_channel->volume >= volume) { player_channel->volume -= volume; } else { player_channel->volume = 0; player_channel->sub_volume = 0; } } else { volume = ((multi_retrigger_volume_change + 0x40) * multi_retrigger_scale) + player_channel->volume; if (volume < 0x100) { player_channel->volume = volume; } else { player_channel->volume = 0xFF; player_channel->sub_volume = 0xFF; } } } else { uint8_t volume_multiplier, volume_divider; volume = (player_channel->volume << 8); if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) volume += player_channel->sub_volume; if ((volume_multiplier = (multi_retrigger_volume_change >> 4))) volume *= volume_multiplier; if ((volume_divider = (multi_retrigger_volume_change & 0xF))) volume /= volume_divider; if (volume > 0xFFFF) volume = 0xFFFF; player_channel->volume = volume >> 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) player_channel->sub_volume = volume; } if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --multi_retrigger_tick) { if (multi_retrigger_tick <= retrigger_tick_count) retrigger_tick_count = -1; } else if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; } player_host_channel->retrig_tick_count = ++retrigger_tick_count; } EXECUTE_EFFECT(extended_ctrl) { const AVSequencerModule *module; AVSequencerPlayerChannel *scan_player_channel; uint8_t extended_control_byte; uint16_t virtual_channel; const uint16_t extended_control_word = data_word & 0x0FFF; switch (data_word >> 12) { case 0 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; if (!extended_control_word) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; break; case 1 : player_host_channel->glissando = extended_control_word; break; case 2 : extended_control_byte = extended_control_word; switch (extended_control_word >> 8) { case 0 : if (!extended_control_byte) extended_control_byte = 1; if (extended_control_byte > 4) extended_control_byte = 4; player_host_channel->multi_retrig_scale = extended_control_byte; break; case 1 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; if (extended_control_byte) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; break; case 2 : if (extended_control_byte) player_host_channel->multi_retrig_tick = player_host_channel->tempo / extended_control_byte; break; } break; case 3 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->mixer.flags = 0; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 4 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 5 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) play_key_off(scan_player_channel); scan_player_channel++; } while (++virtual_channel < module->channels); break; case 6 : player_host_channel->sub_slide = extended_control_word; break; } } EXECUTE_EFFECT(invert_loop) { // TODO: Implement invert loop } EXECUTE_EFFECT(exec_fx) { } EXECUTE_EFFECT(stop_fx) { uint8_t stop_fx = data_word; if ((int8_t) stop_fx < 0) stop_fx = 127; if (!(data_word >>= 8)) data_word = player_host_channel->exec_fx; if (data_word >= player_host_channel->tempo_counter) player_host_channel->effects_used[(stop_fx >> 3)] |= (1 << (7 - (stop_fx & 7))); } EXECUTE_EFFECT(set_volume) { player_host_channel->tremolo_slide = 0; if (check_old_volume(avctx, player_channel, &data_word, channel)) { player_channel->volume = data_word >> 8; player_channel->sub_volume = data_word; } } EXECUTE_EFFECT(volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_ok(player_host_channel, data_word); volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_ok(player_host_channel, data_word); volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->fine_vol_slide_up; do_volume_slide(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_up_once_ok(player_host_channel, data_word); fine_volume_slide_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_volume_slide_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->vol_slide_down; do_volume_slide_down(avctx, player_channel, data_word, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) portamento_down_once_ok(player_host_channel, data_word); fine_volume_slide_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(volume_slide_to) { uint8_t volume_slide_to_value, volume_slide_to_volume; if (!(volume_slide_to_value = (uint8_t) data_word)) volume_slide_to_value = player_host_channel->volume_slide_to; player_host_channel->volume_slide_to = volume_slide_to_value; player_host_channel->volume_slide_to_slide &= 0x00FF; player_host_channel->volume_slide_to_slide += volume_slide_to_value << 8; volume_slide_to_volume = data_word >> 8; if (volume_slide_to_volume && (volume_slide_to_volume < 0xFF)) { player_host_channel->volume_slide_to_volume = volume_slide_to_volume; } else if (volume_slide_to_volume && (player_channel->host_channel == channel)) { const uint16_t volume_slide_target = (volume_slide_to_volume << 8) + player_host_channel->volume_slide_to_volume; uint16_t volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume < volume_slide_target) { do_volume_slide(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target <= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } else { do_volume_slide_down(avctx, player_channel, player_host_channel->volume_slide_to_slide, channel); volume = (player_channel->volume << 8) + player_channel->sub_volume; if (volume_slide_target >= volume) { player_channel->volume = volume_slide_target >> 8; player_channel->sub_volume = volume_slide_target; } } } } EXECUTE_EFFECT(tremolo) { const AVSequencerSong *const song = avctx->player_song; - int16_t tremolo_slide_value; + int32_t tremolo_slide_value; uint8_t tremolo_rate; int16_t tremolo_depth; if (!(tremolo_rate = (data_word >> 8))) tremolo_rate = player_host_channel->tremolo_rate; player_host_channel->tremolo_rate = tremolo_rate; if (!(tremolo_depth = (int8_t) data_word)) tremolo_depth = player_host_channel->tremolo_depth; player_host_channel->tremolo_depth = tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (tremolo_depth > 63) tremolo_depth = 63; if (tremolo_depth < -63) tremolo_depth = -63; } tremolo_slide_value = (-tremolo_depth * run_envelope(avctx, &player_host_channel->tremolo_env, tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) tremolo_slide_value <<= 2; if (player_channel->host_channel == channel) { const uint16_t volume = player_channel->volume; tremolo_slide_value -= player_host_channel->tremolo_slide; if ((int16_t) (tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_host_channel->tremolo_slide -= volume - tremolo_slide_value; } } EXECUTE_EFFECT(set_track_volume) { if (check_old_track_volume(avctx, &data_word)) { player_host_channel->track_volume = data_word >> 8; player_host_channel->track_sub_volume = data_word; } } EXECUTE_EFFECT(track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_host_channel->track_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_up; v5 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_vol_slide_up = data_word; player_host_channel->track_vol_slide_down = v3; player_host_channel->fine_trk_vol_slide_up = v4; player_host_channel->fine_trk_vol_slide_dn = v5; } EXECUTE_EFFECT(track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_host_channel->track_vol_slide_down; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v3 = player_host_channel->fine_trk_vol_slide_up; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = data_word; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_up) { const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_up; do_track_volume_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v4 = player_host_channel->fine_trk_vol_slide_dn; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = data_word; player_host_channel->fine_trk_vol_slide_dn = v4; } EXECUTE_EFFECT(fine_track_volume_slide_down) { const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_host_channel->fine_trk_vol_slide_dn; do_track_volume_slide_down(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_vol_slide_up; v1 = player_host_channel->track_vol_slide_down; v3 = player_host_channel->fine_trk_vol_slide_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_vol_slide_up = v0; player_host_channel->track_vol_slide_down = v1; player_host_channel->fine_trk_vol_slide_up = v3; player_host_channel->fine_trk_vol_slide_dn = data_word; } EXECUTE_EFFECT(track_volume_slide_to) { uint8_t track_vol_slide_to, track_volume_slide_to_volume; if (!(track_vol_slide_to = (uint8_t) data_word)) track_vol_slide_to = player_host_channel->track_vol_slide_to; player_host_channel->track_vol_slide_to = track_vol_slide_to; player_host_channel->track_vol_slide_to_slide &= 0x00FF; player_host_channel->track_vol_slide_to_slide += track_vol_slide_to << 8; track_volume_slide_to_volume = data_word >> 8; if (track_volume_slide_to_volume && (track_volume_slide_to_volume < 0xFF)) { player_host_channel->track_vol_slide_to = track_volume_slide_to_volume; } else if (track_volume_slide_to_volume) { const uint16_t track_volume_slide_target = (track_volume_slide_to_volume << 8) + player_host_channel->track_vol_slide_to_sub_volume; uint16_t track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume < track_volume_slide_target) { do_track_volume_slide(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target <= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } else { do_track_volume_slide_down(avctx, player_host_channel, player_host_channel->track_vol_slide_to_slide); track_volume = (player_host_channel->track_volume << 8) + player_host_channel->track_sub_volume; if (track_volume_slide_target >= track_volume) { player_host_channel->track_volume = track_volume_slide_target >> 8; player_host_channel->track_sub_volume = track_volume_slide_target; } } } } EXECUTE_EFFECT(track_tremolo) { const AVSequencerSong *const song = avctx->player_song; - int16_t track_tremolo_slide_value; + int32_t track_tremolo_slide_value; uint8_t track_tremolo_rate; int16_t track_tremolo_depth; uint16_t track_volume; if (!(track_tremolo_rate = (data_word >> 8))) track_tremolo_rate = player_host_channel->track_trem_rate; player_host_channel->track_trem_rate = track_tremolo_rate; if (!(track_tremolo_depth = (int8_t) data_word)) track_tremolo_depth = player_host_channel->track_trem_depth; player_host_channel->track_trem_depth = track_tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (track_tremolo_depth > 63) track_tremolo_depth = 63; if (track_tremolo_depth < -63) track_tremolo_depth = -63; } track_tremolo_slide_value = (-track_tremolo_depth * run_envelope(avctx, &player_host_channel->track_trem_env, track_tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) track_tremolo_slide_value <<= 2; track_volume = player_host_channel->track_volume; track_tremolo_slide_value -= player_host_channel->track_trem_slide; if ((int16_t) (track_tremolo_slide_value += track_volume) < 0) track_tremolo_slide_value = 0; if (track_tremolo_slide_value > 255) track_tremolo_slide_value = 255; player_host_channel->track_volume = track_tremolo_slide_value; player_host_channel->track_trem_slide -= track_volume - track_tremolo_slide_value; } EXECUTE_EFFECT(set_panning) { const uint8_t panning = data_word >> 8; if (player_channel->host_channel == channel) { player_channel->panning = panning; player_channel->sub_panning = data_word; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = data_word; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = data_word; } EXECUTE_EFFECT(panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->pan_slide_left; do_panning_slide(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v3 = player_host_channel->pan_slide_right; v4 = player_host_channel->fine_pan_slide_left; v5 = player_host_channel->fine_pan_slide_right; v8 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->pan_slide_left = data_word; player_host_channel->pan_slide_right = v3; player_host_channel->fine_pan_slide_left = v4; player_host_channel->fine_pan_slide_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->pan_slide_right; do_panning_slide_right(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v3 = player_host_channel->fine_pan_slide_left; v4 = player_host_channel->fine_pan_slide_right; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = data_word; player_host_channel->fine_pan_slide_left = v3; player_host_channel->fine_pan_slide_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_pan_slide_left; do_panning_slide(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v1 = player_host_channel->pan_slide_right; v4 = player_host_channel->fine_pan_slide_right; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = v1; player_host_channel->fine_pan_slide_left = data_word; player_host_channel->fine_pan_slide_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_pan_slide_right; do_panning_slide_right(avctx, player_host_channel, player_channel, data_word, channel); track = player_host_channel->track; v0 = player_host_channel->pan_slide_left; v1 = player_host_channel->pan_slide_right; v3 = player_host_channel->fine_pan_slide_left; v5 = player_host_channel->panning_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->pan_slide_left = v0; player_host_channel->pan_slide_right = v1; player_host_channel->fine_pan_slide_left = v3; player_host_channel->fine_pan_slide_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(panning_slide_to) { uint8_t panning_slide_to_value, panning_slide_to_panning; if (!(panning_slide_to_value = (uint8_t) data_word)) panning_slide_to_value = player_host_channel->panning_slide_to; player_host_channel->panning_slide_to = panning_slide_to_value; player_host_channel->panning_slide_to_slide &= 0x00FF; player_host_channel->panning_slide_to_slide += panning_slide_to_value << 8; panning_slide_to_panning = data_word >> 8; if (panning_slide_to_panning && (panning_slide_to_panning < 0xFF)) { player_host_channel->panning_slide_to_panning = panning_slide_to_panning; } else if (panning_slide_to_panning && (player_channel->host_channel == channel)) { const uint16_t panning_slide_target = ((uint8_t) panning_slide_to_panning << 8) + player_host_channel->panning_slide_to_sub_panning; uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning < panning_slide_target) { do_panning_slide_right(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target <= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } else { do_panning_slide(avctx, player_host_channel, player_channel, player_host_channel->panning_slide_to_slide, channel); panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (panning_slide_target >= panning) { player_channel->panning = panning_slide_target >> 8; player_channel->sub_panning = panning_slide_target; player_host_channel->panning_slide_to_panning = 0; player_host_channel->track_note_panning = player_host_channel->track_panning = player_host_channel->panning_slide_to_slide >> 8; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_host_channel->panning_slide_to_slide; } } } } EXECUTE_EFFECT(pannolo) { - int16_t pannolo_slide_value; + int32_t pannolo_slide_value; uint8_t pannolo_rate; int16_t pannolo_depth; if (!(pannolo_rate = (data_word >> 8))) pannolo_rate = player_host_channel->pannolo_rate; player_host_channel->pannolo_rate = pannolo_rate; if (!(pannolo_depth = (int8_t) data_word)) pannolo_depth = player_host_channel->pannolo_depth; player_host_channel->pannolo_depth = pannolo_depth; pannolo_slide_value = (-pannolo_depth * run_envelope(avctx, &player_host_channel->pannolo_env, pannolo_rate, 0)) >> 7; if (player_channel->host_channel == channel) { const int16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_host_channel->pannolo_slide; if ((int16_t) (pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_host_channel->pannolo_slide -= panning - pannolo_slide_value; player_host_channel->track_note_panning = player_host_channel->track_panning = panning; player_host_channel->track_note_sub_panning = player_host_channel->track_sub_panning = player_channel->sub_panning; } } EXECUTE_EFFECT(set_track_panning) { player_host_channel->channel_panning = data_word >> 8; player_host_channel->channel_sub_panning = data_word; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; } EXECUTE_EFFECT(track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->track_pan_slide_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v3 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->fine_trk_pan_sld_right; v8 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_host_channel->track_pan_slide_left = data_word; player_host_channel->track_pan_slide_right = v3; player_host_channel->fine_trk_pan_sld_left = v4; player_host_channel->fine_trk_pan_sld_right = v5; player_host_channel->panning_slide_to_slide = v8; } EXECUTE_EFFECT(track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_host_channel->track_pan_slide_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v3 = player_host_channel->fine_trk_pan_sld_left; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = data_word; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_left) { const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_left; do_track_panning_slide(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v4 = player_host_channel->fine_trk_pan_sld_right; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = data_word; player_host_channel->fine_trk_pan_sld_right = v4; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(fine_track_panning_slide_right) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_host_channel->fine_trk_pan_sld_right; do_track_panning_slide_right(avctx, player_host_channel, data_word); track = player_host_channel->track; v0 = player_host_channel->track_pan_slide_left; v1 = player_host_channel->track_pan_slide_right; v3 = player_host_channel->fine_trk_pan_sld_left; v5 = player_host_channel->track_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_host_channel->track_pan_slide_left = v0; player_host_channel->track_pan_slide_right = v1; player_host_channel->fine_trk_pan_sld_left = v3; player_host_channel->fine_trk_pan_sld_right = data_word; player_host_channel->panning_slide_to_slide = v5; } EXECUTE_EFFECT(track_panning_slide_to) { uint8_t track_pan_slide_to, track_panning_slide_to_panning; if (!(track_pan_slide_to = (uint8_t) data_word)) track_pan_slide_to = player_host_channel->track_pan_slide_to; player_host_channel->track_pan_slide_to = track_pan_slide_to; player_host_channel->track_pan_slide_to_slide &= 0x00FF; player_host_channel->track_pan_slide_to_slide += track_pan_slide_to << 8; track_panning_slide_to_panning = data_word >> 8; if (track_panning_slide_to_panning && (track_panning_slide_to_panning < 0xFF)) { player_host_channel->track_pan_slide_to_panning = track_panning_slide_to_panning; } else if (track_panning_slide_to_panning) { const uint16_t track_panning_slide_to_target = ((uint8_t) track_panning_slide_to_panning << 8) + player_host_channel->track_pan_slide_to_sub_panning; uint16_t track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning < track_panning_slide_to_target) { do_track_panning_slide_right(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target <= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } else { do_track_panning_slide(avctx, player_host_channel, player_host_channel->track_pan_slide_to_slide); track_panning = ((uint8_t) player_host_channel->track_panning << 8) + player_host_channel->track_sub_panning; if (track_panning_slide_to_target >= track_panning) { player_host_channel->track_panning = track_panning_slide_to_target >> 8; player_host_channel->track_sub_panning = track_panning_slide_to_target; } } } } EXECUTE_EFFECT(track_pannolo) { - int16_t track_pannolo_slide_value; + int32_t track_pannolo_slide_value; uint8_t track_pannolo_rate; int16_t track_pannolo_depth; uint16_t track_panning; if (!(track_pannolo_rate = (data_word >> 8))) track_pannolo_rate = player_host_channel->track_pan_rate; player_host_channel->track_pan_rate = track_pannolo_rate; if (!(track_pannolo_depth = (int8_t) data_word)) track_pannolo_depth = player_host_channel->track_pan_depth; player_host_channel->track_pan_depth = track_pannolo_depth; track_pannolo_slide_value = (-track_pannolo_depth * run_envelope(avctx, &player_host_channel->track_pan_env, track_pannolo_rate, 0)) >> 7; track_panning = (uint8_t) player_host_channel->track_panning; track_pannolo_slide_value -= player_host_channel->track_pan_slide; if ((int16_t) (track_pannolo_slide_value += track_panning) < 0) track_pannolo_slide_value = 0; if (track_pannolo_slide_value > 255) track_pannolo_slide_value = 255; player_host_channel->track_panning = track_pannolo_slide_value; player_host_channel->track_pan_slide -= track_panning - track_pannolo_slide_value; } EXECUTE_EFFECT(set_tempo) { if (!(player_host_channel->tempo = data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(set_relative_tempo) { if (!(player_host_channel->tempo += data_word)) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } EXECUTE_EFFECT(pattern_break) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = data_word; } } EXECUTE_EFFECT(position_jump) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { AVSequencerOrderData *order_data = NULL; if (data_word--) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; if ((data_word < order_list->orders) && order_list->order_data[data_word]) order_data = order_list->order_data[data_word]; } player_host_channel->order = order_data; pattern_break(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_PATT_BREAK, 0); } } EXECUTE_EFFECT(relative_position_jump) { if (!data_word) data_word = player_host_channel->pos_jump; if ((player_host_channel->pos_jump = data_word)) { const AVSequencerOrderList *order_list = avctx->player_song->order_list + channel; AVSequencerOrderData *order_data = player_host_channel->order; uint32_t ord = -1; while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; ord++; } ord += (int32_t) data_word; if (ord > 0xFFFF) ord = 0; position_jump(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_POS_JUMP, (uint16_t) ord); } } EXECUTE_EFFECT(change_pattern) { player_host_channel->chg_pattern = data_word; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; } EXECUTE_EFFECT(reverse_pattern_play) { if (!data_word) player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else if (data_word & 0x8000) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; else player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS; } EXECUTE_EFFECT(pattern_delay) { player_host_channel->pattern_delay = data_word; } EXECUTE_EFFECT(fine_pattern_delay) { player_host_channel->fine_pattern_delay = data_word; } EXECUTE_EFFECT(pattern_loop) { const AVSequencerSong *const song = avctx->player_song; uint16_t *loop_stack_ptr; uint16_t loop_length = player_host_channel->pattern_loop_depth; loop_stack_ptr = (uint16_t *) avctx->player_globals->loop_stack + (((song->loop_stack_size * channel) * sizeof (uint16_t[2])) + (loop_length * sizeof(uint16_t[2]))); if (data_word) { if (data_word == *loop_stack_ptr) { *loop_stack_ptr = 0; if (loop_length--) player_host_channel->pattern_loop_depth = loop_length; else player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; } else { (*loop_stack_ptr++)++; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; player_host_channel->break_row = *loop_stack_ptr; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; } } else if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; *loop_stack_ptr++ = 0; *loop_stack_ptr = player_host_channel->row; if (++loop_length != song->loop_stack_size) player_host_channel->pattern_loop_depth = loop_length; } } EXECUTE_EFFECT(gosub) { // TODO: Implement GoSub effect } EXECUTE_EFFECT(gosub_return) { // TODO: Implement return effect } EXECUTE_EFFECT(channel_sync) { // TODO: Implement channel synchronizattion effect } EXECUTE_EFFECT(set_sub_slides) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t sub_slide_flags; if (!(sub_slide_flags = (data_word >> 8))) sub_slide_flags = player_host_channel->sub_slide_bits; if (sub_slide_flags & 0x01) player_host_channel->volume_slide_to_volume = data_word; if (sub_slide_flags & 0x02) player_host_channel->track_vol_slide_to_sub_volume = data_word; if (sub_slide_flags & 0x04) player_globals->global_volume_sl_to_sub_volume = data_word; if (sub_slide_flags & 0x08) player_host_channel->panning_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x10) player_host_channel->track_pan_slide_to_sub_panning = data_word; if (sub_slide_flags & 0x20) player_globals->global_pan_slide_to_sub_panning = data_word; } EXECUTE_EFFECT(sample_offset_high) { player_host_channel->smp_offset_hi = data_word; } EXECUTE_EFFECT(sample_offset_low) { if (player_channel->host_channel == channel) { uint32_t sample_offset = (player_host_channel->smp_offset_hi << 16) + data_word; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SMP_OFFSET_REL)) { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SAMPLE_OFFSET) { const AVSequencerSample *const sample = player_channel->sample; if (sample_offset >= sample->samples) return; } player_channel->mixer.pos = 0; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { const uint32_t repeat_end = player_channel->mixer.repeat_start + player_channel->mixer.repeat_length; if (repeat_end < sample_offset) sample_offset = repeat_end; } } player_channel->mixer.pos += sample_offset; } } EXECUTE_EFFECT(set_hold) { // TODO: Implement set hold effect } EXECUTE_EFFECT(set_decay) { // TODO: Implement set decay effect } EXECUTE_EFFECT(set_transpose) { // TODO: Implement set transpose effect } EXECUTE_EFFECT(instrument_ctrl) { // TODO: Implement instrument control effect } EXECUTE_EFFECT(instrument_change) { // TODO: Implement instrument change effect } EXECUTE_EFFECT(set_synth_value) { uint8_t synth_ctrl_count = player_host_channel->synth_ctrl_count; const uint16_t synth_ctrl_change = player_host_channel->synth_ctrl_change & 0x7F; player_host_channel->synth_ctrl = data_word; do { switch (synth_ctrl_change) { case 0x00 : case 0x01 : case 0x02 : case 0x03 : player_channel->entry_pos[synth_ctrl_change & 3] = data_word; break; case 0x04 : case 0x05 : case 0x06 : case 0x07 : player_channel->sustain_pos[synth_ctrl_change & 3] = data_word; break; case 0x08 : case 0x09 : case 0x0A : case 0x0B : player_channel->nna_pos[synth_ctrl_change & 3] = data_word; break; case 0x0C : case 0x0D : case 0x0E : case 0x0F : player_channel->dna_pos[synth_ctrl_change & 3] = data_word; break; case 0x10 : case 0x11 : case 0x12 : case 0x13 : case 0x14 : case 0x15 : case 0x16 : case 0x17 : case 0x18 : case 0x19 : case 0x1A : case 0x1B : case 0x1C : case 0x1D : case 0x1E : case 0x1F : player_channel->variable[synth_ctrl_change & 0xF] = data_word; break; case 0x20 : case 0x21 : case 0x22 : case 0x23 : player_channel->cond_var[synth_ctrl_change & 3] = data_word; break; case 0x24 : if (data_word < player_channel->synth->waveforms) player_channel->sample_waveform = player_channel->waveform_list[data_word]; break; case 0x25 : if (data_word < player_channel->synth->waveforms) player_channel->vibrato_waveform = player_channel->waveform_list[data_word]; break; case 0x26 : if (data_word < player_channel->synth->waveforms) player_channel->tremolo_waveform = player_channel->waveform_list[data_word]; break; case 0x27 : if (data_word < player_channel->synth->waveforms) player_channel->pannolo_waveform = player_channel->waveform_list[data_word]; break; case 0x28 : if (data_word < player_channel->synth->waveforms) player_channel->arpeggio_waveform = player_channel->waveform_list[data_word]; break; } } while (synth_ctrl_count--); } EXECUTE_EFFECT(synth_ctrl) { player_host_channel->synth_ctrl_count = data_word >> 8; player_host_channel->synth_ctrl_change = data_word; if (data_word & 0x80) set_synth_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_SYN_VAL, player_host_channel->synth_ctrl); } static const void *envelope_ctrl_type_lut[] = { use_volume_envelope, use_panning_envelope, use_slide_envelope, use_vibrato_envelope, use_tremolo_envelope, use_pannolo_envelope, use_channolo_envelope, use_spenolo_envelope, use_auto_vibrato_envelope, use_auto_tremolo_envelope, use_auto_pannolo_envelope, use_track_tremolo_envelope, use_track_pannolo_envelope, use_global_tremolo_envelope, use_global_pannolo_envelope, use_arpeggio_envelope, use_resonance_envelope }; EXECUTE_EFFECT(set_envelope_value) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); player_host_channel->env_ctrl = data_word; envelope_get_kind = envelope_ctrl_type_lut[player_host_channel->env_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (player_host_channel->env_ctrl_change) { case 0x00 : if ((data_word < module->envelopes) && ((instrument_envelope = module->envelope_list[data_word]))) envelope->envelope = instrument_envelope; else envelope->envelope = NULL; break; case 0x04 : envelope->pos = data_word; break; case 0x14 : if ((instrument_envelope = envelope->envelope)) { if (++data_word > instrument_envelope->nodes) data_word = instrument_envelope->nodes; envelope->pos = instrument_envelope->node_points[data_word - 1]; } break; case 0x05 : envelope->tempo = data_word; break; case 0x15 : envelope->tempo += data_word; break; case 0x25 : envelope->tempo_count = data_word; break; case 0x06 : envelope->sustain_start = data_word; break; case 0x07 : envelope->sustain_end = data_word; break; case 0x08 : envelope->sustain_count = data_word; break; case 0x09 : envelope->sustain_counted = data_word; break; case 0x0A : envelope->loop_start = data_word; break; case 0x1A : envelope->start = data_word; break; case 0x0B : envelope->loop_end = data_word; break; case 0x1B : envelope->end = data_word; break; case 0x0C : envelope->loop_count = data_word; break; case 0x0D : envelope->loop_counted = data_word; break; case 0x0E : envelope->value_min = data_word; break; case 0x0F : envelope->value_max = data_word; break; } } EXECUTE_EFFECT(envelope_ctrl) { const uint8_t envelope_ctrl_kind = (data_word >> 8) & 0x7F; if (envelope_ctrl_kind <= 0x10) { const uint8_t envelope_ctrl_type = data_word; player_host_channel->env_ctrl_kind = envelope_ctrl_kind; if (envelope_ctrl_type <= 0x32) { const AVSequencerEnvelope *instrument_envelope; AVSequencerPlayerEnvelope *envelope; AVSequencerPlayerEnvelope *(*envelope_get_kind)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel); envelope_get_kind = envelope_ctrl_type_lut[envelope_ctrl_kind]; envelope = envelope_get_kind(avctx, player_host_channel, player_channel); switch (envelope_ctrl_type) { case 0x10 : if ((instrument_envelope = envelope->envelope)) { envelope->tempo = instrument_envelope->tempo; envelope->sustain_counted = 0; envelope->loop_counted = 0; envelope->tempo_count = 0; envelope->sustain_start = instrument_envelope->sustain_start; envelope->sustain_end = instrument_envelope->sustain_end; envelope->sustain_count = instrument_envelope->sustain_count; envelope->loop_start = instrument_envelope->loop_start; envelope->loop_end = instrument_envelope->loop_end; envelope->loop_count = instrument_envelope->loop_count; envelope->value_min = instrument_envelope->value_min; envelope->value_max = instrument_envelope->value_max; envelope->rep_flags = instrument_envelope->flags; set_envelope(player_channel, envelope, envelope->pos); } break; case 0x01 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; @@ -4339,1259 +4339,1259 @@ EXECUTE_EFFECT(envelope_ctrl) case 0x02 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x12 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; break; case 0x22 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x32 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; break; case 0x03 : envelope->flags &= ~AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; case 0x13 : envelope->flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; break; default : player_host_channel->env_ctrl_change = envelope_ctrl_type; if (data_word & 0x8000) set_envelope_value(avctx, player_host_channel, player_channel, channel, AVSEQ_TRACK_EFFECT_CMD_SET_ENV_VAL, player_host_channel->env_ctrl); break; } } } } EXECUTE_EFFECT(nna_ctrl) { const uint8_t nna_ctrl_type = data_word >> 8; uint8_t nna_ctrl_action = data_word; switch (nna_ctrl_type) { case 0x00 : switch (nna_ctrl_action) { case 0x00 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; break; case 0x01 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_OFF; break; case 0x02 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CONTINUE; break; case 0x03 : player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_FADE; break; } break; case 0x11 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct |= nna_ctrl_action; break; case 0x01 : if (!nna_ctrl_action) nna_ctrl_action = 0xFF; player_host_channel->dct &= ~nna_ctrl_action; break; case 0x02 : player_host_channel->dna = nna_ctrl_action; break; } } EXECUTE_EFFECT(loop_ctrl) { // TODO: Implement loop control effect } EXECUTE_EFFECT(set_speed) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_value, speed_min_value, speed_max_value; uint8_t speed_type = data_word >> 12; if ((speed_ptr = get_speed_address(avctx, speed_type, &speed_min_value, &speed_max_value))) { if (!(speed_value = (data_word & 0xFFF))) { if ((data_word & 0x7000) == 0x7000) speed_value = (player_globals->speed_mul << 8U) + player_globals->speed_div; else speed_value = *speed_ptr; } speed_val_ok(avctx, speed_ptr, speed_value, speed_type, speed_min_value, speed_max_value); } } EXECUTE_EFFECT(speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_globals->speed_slide_faster; do_speed_slide(avctx, data_word); track = player_host_channel->track; v3 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_fast; v5 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->speed_slide_faster = data_word; player_globals->speed_slide_slower = v3; player_globals->fine_speed_slide_fast = v4; player_globals->fine_speed_slide_slow = v5; } EXECUTE_EFFECT(speed_slide_slower) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_globals->speed_slide_slower; do_speed_slide_slower(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v3 = player_globals->fine_speed_slide_fast; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = data_word; player_globals->fine_speed_slide_fast = v3; player_globals->fine_speed_slide_slow = v4; } EXECUTE_EFFECT(fine_speed_slide_faster) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_globals->fine_speed_slide_fast; do_speed_slide(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v1 = player_globals->speed_slide_slower; v4 = player_globals->fine_speed_slide_slow; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v0 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = v1; player_globals->fine_speed_slide_fast = data_word; player_globals->fine_speed_slide_slow = v4; } EXECUTE_EFFECT(fine_speed_slide_slower) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_globals->fine_speed_slide_slow; do_speed_slide_slower(avctx, data_word); track = player_host_channel->track; v0 = player_globals->speed_slide_faster; v1 = player_globals->speed_slide_slower; v3 = player_globals->fine_speed_slide_fast; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->speed_slide_faster = v0; player_globals->speed_slide_slower = v1; player_globals->fine_speed_slide_fast = v3; player_globals->fine_speed_slide_slow = data_word; } EXECUTE_EFFECT(speed_slide_to) { // TODO: Implement speed slide to effect } EXECUTE_EFFECT(spenolo) { // TODO: Implement spenolo effect } EXECUTE_EFFECT(channel_ctrl) { const uint8_t channel_ctrl_byte = data_word; switch (data_word >> 8) { case 0x00 : break; case 0x01 : break; case 0x02 : break; case 0x03 : break; case 0x04 : break; case 0x05 : break; case 0x06 : break; case 0x07 : break; case 0x08 : break; case 0x09 : break; case 0x0A : break; case 0x10 : switch (channel_ctrl_byte) { case 0x00 : if (check_surround_track_panning(player_host_channel, player_channel, channel, 0)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } break; case 0x01 : if (check_surround_track_panning(player_host_channel, player_channel, channel, 1)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } break; case 0x10 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; break; case 0x11 : player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN; break; case 0x20 : avctx->player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; break; case 0x21 : avctx->player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; break; } break; case 0x11 : break; } } EXECUTE_EFFECT(set_global_volume) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; if (check_old_track_volume(avctx, &data_word)) { player_globals->global_volume = data_word >> 8; player_globals->global_sub_volume = data_word; } } EXECUTE_EFFECT(global_volume_slide_up) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5; if (!data_word) data_word = player_globals->global_vol_slide_up; do_global_volume_slide(avctx, player_globals, data_word); track = player_host_channel->track; v3 = player_globals->global_vol_slide_down; v4 = player_globals->fine_global_vol_sl_up; v5 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->global_vol_slide_up = data_word; player_globals->global_vol_slide_down = v3; player_globals->fine_global_vol_sl_up = v4; player_globals->fine_global_vol_sl_down = v5; } EXECUTE_EFFECT(global_volume_slide_down) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4; if (!data_word) data_word = player_globals->global_vol_slide_down; do_global_volume_slide_down(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v3 = player_globals->fine_global_vol_sl_up; v4 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v4 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = data_word; player_globals->fine_global_vol_sl_up = v3; player_globals->fine_global_vol_sl_down = v4; } EXECUTE_EFFECT(fine_global_volume_slide_up) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4; if (!data_word) data_word = player_globals->fine_global_vol_sl_up; do_global_volume_slide(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v1 = player_globals->global_vol_slide_down; v4 = player_globals->fine_global_vol_sl_down; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) data_word = v0; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = v1; player_globals->fine_global_vol_sl_up = data_word; player_globals->fine_global_vol_sl_down = v4; } EXECUTE_EFFECT(fine_global_volume_slide_down) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3; if (!data_word) data_word = player_globals->global_vol_slide_down; do_global_volume_slide_down(avctx, player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_vol_slide_up; v1 = player_globals->global_vol_slide_down; v3 = player_globals->fine_global_vol_sl_up; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) v1 = data_word; if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->global_vol_slide_up = v0; player_globals->global_vol_slide_down = v1; player_globals->fine_global_vol_sl_up = v3; player_globals->fine_global_vol_sl_down = data_word; } EXECUTE_EFFECT(global_volume_slide_to) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t global_volume_slide_to_value, global_volume_slide_to_volume; if (!(global_volume_slide_to_value = (uint8_t) data_word)) global_volume_slide_to_value = player_globals->global_volume_slide_to; player_globals->global_volume_slide_to = global_volume_slide_to_value; player_globals->global_volume_slide_to_slide &= 0x00FF; player_globals->global_volume_slide_to_slide += global_volume_slide_to_value << 8; global_volume_slide_to_volume = data_word >> 8; if (global_volume_slide_to_volume && (global_volume_slide_to_volume < 0xFF)) { player_globals->global_volume_sl_to_volume = global_volume_slide_to_volume; } else if (global_volume_slide_to_volume) { const uint16_t global_volume_slide_target = (global_volume_slide_to_volume << 8) + player_globals->global_volume_sl_to_sub_volume; uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume < global_volume_slide_target) { do_global_volume_slide(avctx, player_globals, player_globals->global_volume_slide_to_slide); global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume_slide_target <= global_volume) { player_globals->global_volume = global_volume_slide_target >> 8; player_globals->global_sub_volume = global_volume_slide_target; } } else { do_global_volume_slide_down(avctx, player_globals, player_globals->global_volume_slide_to_slide); global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume_slide_target >= global_volume) { player_globals->global_volume = global_volume_slide_target >> 8; player_globals->global_sub_volume = global_volume_slide_target; } } } } EXECUTE_EFFECT(global_tremolo) { const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; - int16_t global_tremolo_slide_value; + int32_t global_tremolo_slide_value; uint8_t global_tremolo_rate; int16_t global_tremolo_depth; uint16_t global_volume; if (!(global_tremolo_rate = (data_word >> 8))) global_tremolo_rate = player_globals->tremolo_rate; player_globals->tremolo_rate = global_tremolo_rate; if (!(global_tremolo_depth = (int8_t) data_word)) global_tremolo_depth = (int8_t) player_globals->tremolo_depth; player_globals->tremolo_depth = global_tremolo_depth; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) { if (global_tremolo_depth > 63) global_tremolo_depth = 63; if (global_tremolo_depth < -63) global_tremolo_depth = -63; } global_tremolo_slide_value = (-global_tremolo_depth * run_envelope(avctx, &player_globals->tremolo_env, global_tremolo_rate, 0)) >> 7; if (song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES) global_tremolo_slide_value <<= 2; global_volume = player_globals->global_volume; global_tremolo_slide_value -= player_globals->tremolo_slide; if ((int16_t) (global_tremolo_slide_value += global_volume) < 0) global_tremolo_slide_value = 0; if (global_tremolo_slide_value > 255) global_tremolo_slide_value = 255; player_globals->global_volume = global_tremolo_slide_value; player_globals->tremolo_slide -= global_volume - global_tremolo_slide_value; } EXECUTE_EFFECT(set_global_panning) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; player_globals->global_panning = data_word >> 8; player_globals->global_sub_panning = data_word; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; } EXECUTE_EFFECT(global_panning_slide_left) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v3, v4, v5, v8; if (!data_word) data_word = player_globals->global_pan_slide_left; do_global_panning_slide(player_globals, data_word); track = player_host_channel->track; v3 = player_globals->global_pan_slide_right; v4 = player_globals->fine_global_pan_sl_left; v5 = player_globals->fine_global_pan_sl_right; v8 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v3 = data_word; v5 = v4; } player_globals->global_pan_slide_left = data_word; player_globals->global_pan_slide_right = v3; player_globals->fine_global_pan_sl_left = v4; player_globals->fine_global_pan_sl_right = v5; player_globals->global_pan_slide_to_slide = v8; } EXECUTE_EFFECT(global_panning_slide_right) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v3, v4, v5; if (!data_word) data_word = player_globals->global_pan_slide_right; do_global_panning_slide_right(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v3 = player_globals->fine_global_pan_sl_left; v4 = player_globals->fine_global_pan_sl_right; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v4 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = data_word; v3 = v4; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = data_word; player_globals->fine_global_pan_sl_left = v3; player_globals->fine_global_pan_sl_right = v4; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(fine_global_panning_slide_left) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v4, v5; if (!data_word) data_word = player_globals->fine_global_pan_sl_left; do_global_panning_slide(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v1 = player_globals->global_pan_slide_right; v4 = player_globals->fine_global_pan_sl_right; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v0 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v1 = v0; v4 = data_word; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = v1; player_globals->fine_global_pan_sl_left = data_word; player_globals->fine_global_pan_sl_right = v4; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(fine_global_panning_slide_right) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; const AVSequencerTrack *track; uint16_t v0, v1, v3, v5; if (!data_word) data_word = player_globals->fine_global_pan_sl_right; do_global_panning_slide_right(player_globals, data_word); track = player_host_channel->track; v0 = player_globals->global_pan_slide_left; v1 = player_globals->global_pan_slide_right; v3 = player_globals->fine_global_pan_sl_left; v5 = player_globals->global_pan_slide_to_slide; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { v1 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { v0 = v1; v3 = data_word; } player_globals->global_pan_slide_left = v0; player_globals->global_pan_slide_right = v1; player_globals->fine_global_pan_sl_left = v3; player_globals->fine_global_pan_sl_right = data_word; player_globals->global_pan_slide_to_slide = v5; } EXECUTE_EFFECT(global_panning_slide_to) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint8_t global_pan_slide_to, global_pan_slide_to_panning; if (!(global_pan_slide_to = (uint8_t) data_word)) global_pan_slide_to = player_globals->global_pan_slide_to; player_globals->global_pan_slide_to = global_pan_slide_to; player_globals->global_pan_slide_to_slide &= 0x00FF; player_globals->global_pan_slide_to_slide += global_pan_slide_to << 8; global_pan_slide_to_panning = data_word >> 8; if (global_pan_slide_to_panning && (global_pan_slide_to_panning < 0xFF)) { player_globals->global_pan_slide_to_panning = global_pan_slide_to_panning; } else if (global_pan_slide_to_panning) { const uint16_t global_panning_slide_target = ((uint8_t) global_pan_slide_to_panning << 8) + player_globals->global_pan_slide_to_sub_panning; uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning < global_panning_slide_target) { do_global_panning_slide_right(player_globals, player_globals->global_pan_slide_to_slide); global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning_slide_target <= global_panning) { player_globals->global_panning = global_panning_slide_target >> 8; player_globals->global_sub_panning = global_panning_slide_target; } } else { do_global_panning_slide(player_globals, player_globals->global_pan_slide_to_slide); global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; if (global_panning_slide_target >= global_panning) { player_globals->global_panning = global_panning_slide_target >> 8; player_globals->global_sub_panning = global_panning_slide_target; } } } } EXECUTE_EFFECT(global_pannolo) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; - int16_t global_pannolo_slide_value; + int32_t global_pannolo_slide_value; uint8_t global_pannolo_rate; int16_t global_pannolo_depth; uint16_t global_panning; if (!(global_pannolo_rate = (data_word >> 8))) global_pannolo_rate = player_globals->pannolo_rate; player_globals->pannolo_rate = global_pannolo_rate; if (!(global_pannolo_depth = (int8_t) data_word)) global_pannolo_depth = player_globals->pannolo_depth; player_globals->pannolo_depth = global_pannolo_depth; global_pannolo_slide_value = (-global_pannolo_depth * run_envelope(avctx, &player_globals->pannolo_env, global_pannolo_rate, 0)) >> 7; global_panning = (uint8_t) player_globals->global_panning; global_pannolo_slide_value -= player_globals->pannolo_slide; if ((int16_t) (global_pannolo_slide_value += global_panning) < 0) global_pannolo_slide_value = 0; if (global_pannolo_slide_value > 255) global_pannolo_slide_value = 255; player_globals->global_panning = global_pannolo_slide_value; player_globals->pannolo_slide -= global_panning - global_pannolo_slide_value; } EXECUTE_EFFECT(user_sync) { } static void se_vibrato_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t vibrato_slide_value) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; uint32_t old_frequency = player_channel->frequency; player_channel->frequency -= player_channel->vibrato_slide; if (vibrato_slide_value < 0) { vibrato_slide_value = -vibrato_slide_value; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_up(avctx, player_channel, player_channel->frequency, vibrato_slide_value); else amiga_slide_up(player_channel, player_channel->frequency, vibrato_slide_value); } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) { linear_slide_down(avctx, player_channel, player_channel->frequency, vibrato_slide_value); } else { amiga_slide_down(player_channel, player_channel->frequency, vibrato_slide_value); } player_channel->vibrato_slide -= old_frequency - player_channel->frequency; } static void se_arpegio_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const int16_t arpeggio_transpose, uint16_t arpeggio_finetune) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_frequency, old_frequency; uint16_t octave; int16_t note; octave = arpeggio_transpose / 12; note = arpeggio_transpose % 12; if (note < 0) { octave--; note += 12; arpeggio_finetune = -arpeggio_finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (int32_t) (arpeggio_finetune * (int16_t) next_frequency) >> 8; if ((int16_t) (octave) < 0) { octave = -octave; frequency >>= octave; } else { frequency <<= octave; } old_frequency = player_channel->frequency; slide_frequency = player_channel->arpeggio_slide + old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_frequency) >> 16; player_channel->arpeggio_slide += old_frequency - frequency; } static void se_tremolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t tremolo_slide_value) { uint16_t volume = player_channel->volume; tremolo_slide_value -= player_channel->tremolo_slide; if ((tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_channel->tremolo_slide -= volume - tremolo_slide_value; } static void se_pannolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t pannolo_slide_value) { uint16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_channel->pannolo_slide; if ((pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_channel->pannolo_slide -= panning - pannolo_slide_value; } #define EXECUTE_SYNTH_CODE_INSTRUCTION(fx_type) \ static uint16_t se_##fx_type(AVSequencerContext *const avctx, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t virtual_channel, \ uint16_t synth_code_line, \ const int src_var, \ int dst_var, \ uint16_t instruction_data, \ const int synth_type) EXECUTE_SYNTH_CODE_INSTRUCTION(stop) { instruction_data += player_channel->variable[src_var]; if (instruction_data & 0x8000) player_channel->stop_forbid_mask &= ~instruction_data; else player_channel->stop_forbid_mask |= instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(kill) { instruction_data += player_channel->variable[src_var]; player_channel->kill_count[synth_type] = instruction_data; player_channel->synth_flags |= 1 << synth_type; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(wait) { instruction_data += player_channel->variable[src_var]; player_channel->wait_count[synth_type] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitvol) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitpan) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~1; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitsld) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~2; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitspc) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~3; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jump) { instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpeq) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpne) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppl) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpmi) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumplt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumple) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpgt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!(synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpge) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpls) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if ((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumphi) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvol) { if (!(player_channel->stop_forbid_mask & 1)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[0] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppan) { if (!(player_channel->stop_forbid_mask & 2)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[1] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpsld) { if (!(player_channel->stop_forbid_mask & 4)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[2] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpspc) { if (!(player_channel->stop_forbid_mask & 8)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[3] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(call) { player_channel->variable[dst_var] = synth_code_line; instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(ret) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = --synth_code_line; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(posvar) { player_channel->variable[src_var] += synth_code_line + --instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(load) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(add) { uint16_t flags = 0; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int16_t) player_channel->variable[dst_var] + (int16_t) instruction_data; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; player_channel->variable[dst_var] = add_data; if (player_channel->variable[dst_var] < instruction_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (!add_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(addx) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; uint32_t add_unsigned_data; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int16_t) player_channel->variable[dst_var] + (int16_t) instruction_data; add_unsigned_data = instruction_data; if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND) { add_data++; add_unsigned_data++; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) ++instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } else if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } player_channel->variable[dst_var] = add_data; if ((player_channel->variable[dst_var] < add_unsigned_data)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (add_data) flags &= ~AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(sub) {
BastyCDGS/ffmpeg-soc
366787943097923c48152c8684dfefd579e9852b
Fixed one unnecessary parenthesis in low quality mixer.
diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index a4339ed..1d42a46 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -3273,1019 +3273,1019 @@ static void set_mix_functions(const AV_LQMixerData *const mixer_data, struct Cha if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround_16_to_8; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } static void update_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } static void set_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_LQMixerData *lq_mixer_data; AV_LQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned interpolation = 0, real16bit = 0, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(lq_mixer_data = av_mallocz(sizeof(AV_LQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(lq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mixer_data.mixctx = mixctx; buf_size = lq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=true;") || av_stristr(args, "real16bit=enabled;")) real16bit = 1; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (av_stristr(args, "interpolation=true;") || av_stristr(args, "interpolation=enabled;")) interpolation = 2; else if ((cfg_buf = av_stristr(args, "interpolation="))) sscanf(cfg_buf, "interpolation=%d;", &interpolation); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->channel_info = channel_info; lq_mixer_data->mixer_data.channels_in = channels_in; lq_mixer_data->channels_in = channels_in; lq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mix_buf_size = mix_buf_mem_size; lq_mixer_data->buf = buf; lq_mixer_data->buf_size = buf_size; lq_mixer_data->mixer_data.mix_buf_size = lq_mixer_data->buf_size; lq_mixer_data->mixer_data.mix_buf = lq_mixer_data->buf; channel_rate = lq_mixer_data->mixer_data.mixctx->frequency; lq_mixer_data->mixer_data.rate = channel_rate; lq_mixer_data->mix_rate = channel_rate; lq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; lq_mixer_data->interpolation = interpolation >= 2 ? 2 : interpolation; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->filter_buf = buf; for (i = lq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) lq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_LQMixerData *lq_mixer_data = (AV_LQMixerData *) mixer_data; if (!lq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->filter_buf); av_free(lq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t channel_rate = lq_mixer_data->mix_rate * 10; uint64_t pass_value; lq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) lq_mixer_data->mix_rate_frac >> 16); lq_mixer_data->pass_len = (uint64_t) pass_value / lq_mixer_data->mixer_data.tempo; lq_mixer_data->pass_len_frac = (((uint64_t) pass_value % lq_mixer_data->mixer_data.tempo) << 32) / lq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; lq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = lq_mixer_data->mixer_data.mix_buf_size; lq_mixer_data->mixer_data.channels_out = new_channels; if ((lq_mixer_data->buf_size * lq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = lq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = lq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return lq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return lq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); lq_mixer_data->mixer_data.mix_buf = buf; lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = new_channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; update_sample_filter(lq_mixer_data, &channel_info->current); update_sample_filter(lq_mixer_data, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; - if (((old_channels = lq_mixer_data->channels_in) != channels) && (!(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE)))) { + if (((old_channels = lq_mixer_data->channels_in) != channels) && !(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { int32_t *volume_lut = lq_mixer_data->volume_lut; int32_t volume_mult = 0, volume_div = channels << 8; uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_info->filter_tmp1 = 0; channel_info->filter_tmp2 = 0; set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; set_sample_filter(lq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, }; #endif /* CONFIG_LOW_QUALITY_MIXER */
BastyCDGS/ffmpeg-soc
b9c340a4fe000b9517de43a4b8822fd524fc2a30
Fixed copyright year in high quality mixer to reflect current year instead of 2010.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index ca31752..6c397d5 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1,515 +1,515 @@ /* * Sequencer high quality integer mixer - * Copyright (c) 2010 Sebastian Vater <[email protected]> + * Copyright (c) 2011 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer high quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_HQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_HQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_HQMixerData; typedef struct AV_HQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t div_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; void (*mix_backwards_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint8_t filter_cutoff; uint8_t filter_damping; } current; struct ChannelBlock next; int32_t filter_tmp1; int32_t filter_tmp2; int32_t prev_sample; int32_t curr_sample; int32_t next_sample; int32_t prev_sample_r; int32_t curr_sample_r; int32_t next_sample_r; int mix_right; } AV_HQMixerChannelInfo; #if CONFIG_HIGH_QUALITY_MIXER static const char *high_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_high_quality_mixer_class = { "AVSequencer High Quality Mixer", high_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(AV_HQMixerChannelInfo *channel_info, struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; int32_t c1 = channel_block->filter_c1; int32_t c2 = channel_block->filter_c2; int32_t c3 = channel_block->filter_c3; int32_t o1 = channel_info->filter_tmp2; int32_t o2 = channel_info->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_info->filter_tmp1 = o2; channel_info->filter_tmp2 = o1; } static void mix_sample(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint32_t counted; uint32_t count_restart; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { counted = channel_info->current.counted++; if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(channel_info, &channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { counted = channel_info->current.counted++; if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } #define MIX(type) \ static void mix_##type(const AV_HQMixerData *const mixer_data, \ struct AV_HQMixerChannelInfo *const channel_info, \ struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } static void get_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset + 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int8_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset - 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16_to_8(struct AV_HQMixerChannelInfo *const channel_info, struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; volume_lut = channel_info->mix_right ? channel_next_block->volume_right_lut : channel_next_block->volume_left_lut;
BastyCDGS/ffmpeg-soc
be2bf000c5df4b9204f3658691016d827707f315
Removed parenthesis not necessary (nit cleanup) in module playback handler.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 37f76a9..e4aa57c 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -1,894 +1,894 @@ /* * Sequencer main playback handler * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer main playback handler. */ #include <stddef.h> #include <string.h> #include "libavutil/intreadwrite.h" #include "libavsequencer/avsequencer.h" #include "libavsequencer/player.h" #define AVSEQ_RANDOM_CONST -1153374675 #define AVSEQ_SLIDE_CONST (8363*1712*4) #define ASSIGN_INSTRUMENT_ENVELOPE(env_type) \ static const AVSequencerEnvelope *assign_##env_type##_envelope(const AVSequencerContext *const avctx, \ const AVSequencerInstrument *const instrument, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const AVSequencerEnvelope **envelope, \ AVSequencerPlayerEnvelope **player_envelope) ASSIGN_INSTRUMENT_ENVELOPE(volume) { if (instrument) *envelope = instrument->volume_env; *player_envelope = &player_channel->vol_env; return player_host_channel->prev_volume_env; } ASSIGN_INSTRUMENT_ENVELOPE(panning) { if (instrument) *envelope = instrument->panning_env; *player_envelope = &player_channel->pan_env; return player_host_channel->prev_panning_env; } ASSIGN_INSTRUMENT_ENVELOPE(slide) { if (instrument) *envelope = instrument->slide_env; *player_envelope = &player_channel->slide_env; return player_host_channel->prev_slide_env; } ASSIGN_INSTRUMENT_ENVELOPE(vibrato) { if (instrument) *envelope = instrument->vibrato_env; *player_envelope = &player_host_channel->vibrato_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &player_host_channel->tremolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &player_host_channel->pannolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(channolo) { if (instrument) *envelope = instrument->channolo_env; *player_envelope = &player_host_channel->channolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(spenolo) { if (instrument) *envelope = instrument->spenolo_env; *player_envelope = &avctx->player_globals->spenolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(track_tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &player_host_channel->track_trem_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(track_pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &player_host_channel->track_pan_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(global_tremolo) { if (instrument) *envelope = instrument->tremolo_env; *player_envelope = &avctx->player_globals->tremolo_env; return (*player_envelope)->envelope; } ASSIGN_INSTRUMENT_ENVELOPE(global_pannolo) { if (instrument) *envelope = instrument->pannolo_env; *player_envelope = &avctx->player_globals->pannolo_env; return (*player_envelope)->envelope; } #define ASSIGN_SAMPLE_ENVELOPE(env_type) \ static const AVSequencerEnvelope *assign_##env_type##_envelope(const AVSequencerSample *const sample, \ AVSequencerPlayerChannel *const player_channel, \ AVSequencerPlayerEnvelope **player_envelope) \ ASSIGN_SAMPLE_ENVELOPE(auto_vibrato) { *player_envelope = &player_channel->auto_vib_env; return sample->auto_vibrato_env; } ASSIGN_SAMPLE_ENVELOPE(auto_tremolo) { *player_envelope = &player_channel->auto_trem_env; return sample->auto_tremolo_env; } ASSIGN_SAMPLE_ENVELOPE(auto_pannolo) { *player_envelope = &player_channel->auto_pan_env; return sample->auto_pannolo_env; } ASSIGN_INSTRUMENT_ENVELOPE(resonance) { if (instrument) *envelope = instrument->resonance_env; *player_envelope = &player_channel->resonance_env; return player_host_channel->prev_resonance_env; } #define USE_ENVELOPE(env_type) \ static AVSequencerPlayerEnvelope *use_##env_type##_envelope(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel) USE_ENVELOPE(volume) { return &player_channel->vol_env; } USE_ENVELOPE(panning) { return &player_channel->pan_env; } USE_ENVELOPE(slide) { return &player_channel->slide_env; } USE_ENVELOPE(vibrato) { return &player_host_channel->vibrato_env; } USE_ENVELOPE(tremolo) { return &player_host_channel->tremolo_env; } USE_ENVELOPE(pannolo) { return &player_host_channel->pannolo_env; } USE_ENVELOPE(channolo) { return &player_host_channel->channolo_env; } USE_ENVELOPE(spenolo) { return &avctx->player_globals->spenolo_env; } USE_ENVELOPE(auto_vibrato) { return &player_channel->auto_vib_env; } USE_ENVELOPE(auto_tremolo) { return &player_channel->auto_trem_env; } USE_ENVELOPE(auto_pannolo) { return &player_channel->auto_pan_env; } USE_ENVELOPE(track_tremolo) { return &player_host_channel->track_trem_env; } USE_ENVELOPE(track_pannolo) { return &player_host_channel->track_pan_env; } USE_ENVELOPE(global_tremolo) { return &avctx->player_globals->tremolo_env; } USE_ENVELOPE(global_pannolo) { return &avctx->player_globals->pannolo_env; } USE_ENVELOPE(arpeggio) { return &player_host_channel->arpepggio_env; } USE_ENVELOPE(resonance) { return &player_channel->resonance_env; } #define PRESET_EFFECT(fx_type) \ static void preset_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t data_word) PRESET_EFFECT(tone_portamento) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA; } PRESET_EFFECT(vibrato) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO; } PRESET_EFFECT(note_delay) { if ((player_host_channel->note_delay = data_word)) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = player_host_channel->note_delay; } } } PRESET_EFFECT(tremolo) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO; } PRESET_EFFECT(set_transpose) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE; player_host_channel->transpose = data_word >> 8; player_host_channel->trans_finetune = data_word; } static const int32_t portamento_mask[8] = { 0, 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE }; static const int32_t portamento_trigger_mask[6] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN }; #define CHECK_EFFECT(fx_type) \ static void check_##fx_type(const AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ uint16_t *const fx_byte, \ uint16_t *const data_word, \ uint16_t *const flags) CHECK_EFFECT(portamento) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE); player_host_channel->fine_slide_flags |= portamento_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { if ((*fx_byte <= AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN) && (!(player_host_channel->fine_slide_flags & (AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE)))) goto trigger_portamento_done; *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PORTA) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_PORTA_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PORTA_ONCE) *fx_byte += AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_PORTA_UP; } - if ((!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) && (*fx_byte > AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN)) { + if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES) && (*fx_byte > AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; *fx_byte &= -2; if (player_host_channel->fine_slide_flags & portamento_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PORTA_DOWN - 1)]) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PORTA_UP - AVSEQ_TRACK_EFFECT_CMD_ARPEGGIO; } trigger_portamento_done: *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_O_PORTA_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(tone_portamento) { } CHECK_EFFECT(note_slide) { uint8_t note_slide_type; if (!(note_slide_type = (*data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; if (note_slide_type & 0xF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE }; static const int32_t volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN }; CHECK_EFFECT(volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE); player_host_channel->fine_slide_flags |= volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; *fx_byte &= -2; if (volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_VOL_SLD_UP - AVSEQ_TRACK_EFFECT_CMD_SET_VOLUME; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_VOLSL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(volume_slide_to) { if ((*data_word >> 8) == 0xFF) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } static const int32_t track_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE }; static const int32_t track_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN }; CHECK_EFFECT(track_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE); player_host_channel->fine_slide_flags |= track_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; *fx_byte &= -2; if (track_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TVOL_SL_UP - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_VOL; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TVOL_SL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE }; static const int32_t panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT }; CHECK_EFFECT(panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE); player_host_channel->fine_slide_flags |= panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; *fx_byte &= -2; if (panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_PAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_PANNING; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_P_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t track_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE }; static const int32_t track_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT }; CHECK_EFFECT(track_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_TRACK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRK_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE); player_host_channel->fine_slide_flags |= track_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_TRACK_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; *fx_byte &= -2; if (track_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_TPAN_SL_LEFT - AVSEQ_TRACK_EFFECT_CMD_SET_TRK_PAN; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_TP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t speed_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE }; static const int32_t speed_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER }; CHECK_EFFECT(speed_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE_SLOWER|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE); player_host_channel->fine_slide_flags |= speed_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_SPEED_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte -= AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; *fx_byte &= -2; if (speed_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; *fx_byte += AVSEQ_TRACK_EFFECT_CMD_SPD_SLD_FAST - AVSEQ_TRACK_EFFECT_CMD_SET_SPEED; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_S_SLD_FAST) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } CHECK_EFFECT(channel_control) { } static const int32_t global_volume_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE }; static const int32_t global_volume_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN }; CHECK_EFFECT(global_volume_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_VOL_SLIDE_DOWN|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE); player_host_channel->fine_slide_flags |= global_volume_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_VOL_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_volume_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_G_VOLSL_UP)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_F_G_VOL_UP) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static const int32_t global_panning_slide_mask[4] = { 0, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE }; static const int32_t global_panning_slide_trigger_mask[4] = { AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT, AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT }; CHECK_EFFECT(global_panning_slide) { if (*data_word) { player_host_channel->fine_slide_flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_GLOBAL_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOB_PAN_SLIDE_RIGHT|AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE); player_host_channel->fine_slide_flags |= global_panning_slide_mask[(*fx_byte - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)]; } else { const AVSequencerTrack *const track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_SLIDES) { *fx_byte = AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT; if (player_host_channel->fine_slide_flags & AVSEQ_PLAYER_HOST_CHANNEL_FINE_SLIDE_FLAG_FINE_GLOBAL_PAN_SLIDE) *fx_byte = AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_VOLUME_SLIDES)) { const uint16_t mask_volume_fx = *fx_byte; *fx_byte &= -2; if (global_panning_slide_trigger_mask[(mask_volume_fx - AVSEQ_TRACK_EFFECT_CMD_GPANSL_LEFT)] & player_host_channel->fine_slide_flags) *fx_byte |= 1; } *flags |= AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; if (*fx_byte >= AVSEQ_TRACK_EFFECT_CMD_FGP_SL_LEFT) *flags &= ~AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW; } } static int16_t step_envelope(AVSequencerContext *const avctx, AVSequencerPlayerEnvelope *const player_envelope, const int16_t *const envelope_data, uint16_t envelope_pos, const uint16_t tempo_multiplier, const int16_t value_adjustment) { uint32_t seed, randomize_value; const uint16_t envelope_restart = player_envelope->start; int16_t value; value = envelope_data[envelope_pos]; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM) { avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; randomize_value = ((uint16_t) player_envelope->value_max - (uint16_t) player_envelope->value_min) + 1; value = ((uint64_t) seed * randomize_value) >> 32; value += player_envelope->value_min; } value += value_adjustment; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS) { if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over_back; for (;;) { check_back_envelope_loop: if (envelope_pos <= envelope_restart) break; loop_envelope_over_back: if (envelope_restart == player_envelope->end) goto run_envelope_check_pingpong_wait; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + envelope_restart; if (envelope_pos < envelope_restart) goto check_envelope_loop; goto loop_envelope_over; } else { envelope_pos += player_envelope->end - envelope_restart; } } } else { if (envelope_pos < tempo_multiplier) player_envelope->tempo = 0; envelope_pos -= tempo_multiplier; } } else if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING) { envelope_pos += tempo_multiplier; if (envelope_pos < tempo_multiplier) goto loop_envelope_over; for (;;) { check_envelope_loop: if (envelope_pos <= player_envelope->end) break; loop_envelope_over: if (envelope_restart == player_envelope->end) { run_envelope_check_pingpong_wait: envelope_pos = envelope_restart; if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; break; } if (player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_PINGPONG) { player_envelope->flags ^= AVSEQ_PLAYER_ENVELOPE_FLAG_BACKWARDS; envelope_pos -= player_envelope->pos; envelope_pos += -envelope_pos + player_envelope->end; if (envelope_pos < player_envelope->end) goto check_back_envelope_loop; goto loop_envelope_over_back; } else { envelope_pos += envelope_restart - player_envelope->end; } } } else { envelope_pos += tempo_multiplier; if ((envelope_pos < tempo_multiplier) || (envelope_pos > player_envelope->end)) player_envelope->tempo = 0; } player_envelope->pos = envelope_pos; if ((player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD) && (!(player_envelope->flags & AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM))) value = envelope_data[envelope_pos] + value_adjustment; return value; } static void set_envelope(AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope *const envelope, uint16_t envelope_pos) { const AVSequencerEnvelope *instrument_envelope; uint8_t envelope_flags; uint16_t envelope_loop_start, envelope_loop_end; if (!(instrument_envelope = envelope->envelope)) return; envelope_flags = AVSEQ_PLAYER_ENVELOPE_FLAG_LOOPING; envelope_loop_start = envelope->loop_start; envelope_loop_end = envelope->loop_end; if ((envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_SUSTAIN) && (!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SUSTAIN))) { envelope_loop_start = envelope->sustain_start; envelope_loop_end = envelope->sustain_end; } else if (!(envelope->rep_flags & AVSEQ_PLAYER_ENVELOPE_REP_FLAG_LOOP)) { envelope_flags = 0; envelope_loop_end = instrument_envelope->points - 1; } if (envelope_loop_start > envelope_loop_end) envelope_loop_start = envelope_loop_end; if (envelope_pos > envelope_loop_end) envelope_pos = envelope_loop_end; envelope->pos = envelope_pos; envelope->start = envelope_loop_start; envelope->end = envelope_loop_end; @@ -1977,1025 +1977,1025 @@ static void speed_val_ok(const AVSequencerContext *const avctx, uint16_t *const player_globals->tempo = tempo; tempo *= player_globals->relative_speed; tempo >>= 16; if (mixer->mixctx->set_tempo) mixer->mixctx->set_tempo(mixer, tempo); } } static void do_speed_slide(const AVSequencerContext *const avctx, uint16_t data_word) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_min_value, speed_max_value; if ((speed_ptr = get_speed_address(avctx, player_globals->speed_type, &speed_min_value, &speed_max_value))) { uint16_t speed_value; if ((player_globals->speed_type & 0x07) == 0x07) speed_value = (player_globals->speed_mul << 8) + player_globals->speed_div; else speed_value = *speed_ptr; if ((speed_value += data_word) < data_word) speed_value = 0xFFFF; speed_val_ok(avctx, speed_ptr, speed_value, player_globals->speed_type, speed_min_value, speed_max_value); } } static void do_speed_slide_slower(const AVSequencerContext *const avctx, uint16_t data_word) { AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t *speed_ptr; uint16_t speed_min_value, speed_max_value; if ((speed_ptr = get_speed_address(avctx, player_globals->speed_type, &speed_min_value, &speed_max_value))) { uint16_t speed_value; if ((player_globals->speed_type & 0x07) == 0x07) speed_value = (player_globals->speed_mul << 8) + player_globals->speed_div; else speed_value = *speed_ptr; if (speed_value < data_word) data_word = speed_value; speed_value -= data_word; speed_val_ok(avctx, speed_ptr, speed_value, player_globals->speed_type, speed_min_value, speed_max_value); } } static void do_global_volume_slide(const AVSequencerContext *const avctx, AVSequencerPlayerGlobals *player_globals, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if ((global_volume += data_word) < data_word) global_volume = 0xFFFF; player_globals->global_volume = global_volume >> 8; player_globals->global_sub_volume = global_volume; } } static void do_global_volume_slide_down(const AVSequencerContext *const avctx, AVSequencerPlayerGlobals *player_globals, uint16_t data_word) { if (check_old_track_volume(avctx, &data_word)) { uint16_t global_volume = (player_globals->global_volume << 8) + player_globals->global_sub_volume; if (global_volume < data_word) data_word = global_volume; global_volume -= data_word; player_globals->global_volume = global_volume >> 8; player_globals->global_sub_volume = global_volume; } } static void do_global_panning_slide(AVSequencerPlayerGlobals *player_globals, uint16_t data_word) { uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; if ((global_panning += data_word) < data_word) global_panning = 0xFFFF; player_globals->global_panning = global_panning >> 8; player_globals->global_sub_panning = global_panning; } static void do_global_panning_slide_right(AVSequencerPlayerGlobals *player_globals, uint16_t data_word) { uint16_t global_panning = ((uint8_t) player_globals->global_panning << 8) + player_globals->global_sub_panning; player_globals->flags &= ~AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND; if (global_panning < data_word) data_word = global_panning; global_panning -= data_word; player_globals->global_panning = global_panning >> 8; player_globals->global_sub_panning = global_panning; } #define EXECUTE_EFFECT(fx_type) \ static void fx_type(AVSequencerContext *const avctx, \ AVSequencerPlayerHostChannel *const player_host_channel, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t channel, \ const unsigned fx_byte, \ uint16_t data_word) EXECUTE_EFFECT(arpeggio) { int8_t first_arpeggio, second_arpeggio; int16_t arpeggio_value; if (!data_word) data_word = (player_host_channel->arpeggio_first << 8) + player_host_channel->arpeggio_second; player_host_channel->arpeggio_first = first_arpeggio = data_word >> 8; player_host_channel->arpeggio_second = second_arpeggio = data_word; switch (player_host_channel->arpeggio_tick) { case 0 : arpeggio_value = 0; break; case 1 : arpeggio_value = first_arpeggio; break; default : arpeggio_value = second_arpeggio; player_host_channel->arpeggio_tick -= 3; break; } if (player_channel->host_channel == channel) { uint32_t frequency, arpeggio_freq, old_frequency; uint16_t octave; int16_t note; octave = arpeggio_value / 12; note = arpeggio_value % 12; if (note < 0) { octave--; note += 12; } old_frequency = player_channel->frequency; frequency = old_frequency + player_host_channel->arpeggio_freq; arpeggio_freq = (avctx->frequency_lut ? avctx->frequency_lut[note + 1] : pitch_lut[note + 1]); if ((int16_t) octave < 0) { octave = -octave; arpeggio_freq = ((uint64_t) frequency * arpeggio_freq) >> (16 + octave); } else { arpeggio_freq <<= octave; arpeggio_freq = ((uint64_t) frequency * arpeggio_freq) >> 16; } player_host_channel->arpeggio_freq += old_frequency - arpeggio_freq; player_channel->frequency = arpeggio_freq; } player_host_channel->arpeggio_tick++; } EXECUTE_EFFECT(portamento_up) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_up; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_up_ok(player_host_channel, data_word); portamento_up_ok(player_host_channel, data_word); } EXECUTE_EFFECT(portamento_down) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_down; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_down_ok(player_host_channel, data_word); portamento_down_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_portamento_up) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_up; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = data_word; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->tone_porta_once; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = data_word; player_host_channel->tone_porta_once = v4; player_host_channel->fine_tone_porta_once = v8; } } EXECUTE_EFFECT(fine_portamento_down) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->porta_up_once; v4 = player_host_channel->porta_down_once; v5 = player_host_channel->fine_porta_up_once; v8 = player_host_channel->fine_porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = data_word; v4 = data_word; v8 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up = data_word; v0 = v1; v3 = v4; v5 = v8; } player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = v3; player_host_channel->porta_down_once = v4; player_host_channel->fine_porta_up_once = v5; player_host_channel->fine_porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->tone_porta_once; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = data_word; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = v5; } } EXECUTE_EFFECT(portamento_up_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); portamento_up_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(portamento_down_once) { const AVSequencerTrack *track; if (!data_word) data_word = player_host_channel->porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); portamento_down_once_ok(player_host_channel, data_word); } EXECUTE_EFFECT(fine_portamento_up_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_up_once; portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_up_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_down_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_up_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v1 = player_host_channel->tone_porta; v4 = player_host_channel->fine_tone_porta; v8 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v1 = v0; v4 = v3; v8 = v5; } player_host_channel->tone_porta = v1; player_host_channel->fine_tone_porta = v4; player_host_channel->tone_porta_once = v8; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(fine_portamento_down_once) { const AVSequencerTrack *track; uint16_t v0, v1, v3, v4, v5, v8; if (!data_word) data_word = player_host_channel->fine_porta_down_once; portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); track = player_host_channel->track; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_VOLUME_PITCH) fine_volume_slide_down_ok(player_host_channel, data_word); v0 = player_host_channel->porta_up; v1 = player_host_channel->porta_down; v3 = player_host_channel->fine_porta_up; v4 = player_host_channel->fine_porta_down; v5 = player_host_channel->porta_up_once; v8 = player_host_channel->porta_down_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v3 = data_word; v5 = data_word; } if (!(track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_OP_SLIDES)) { player_host_channel->fine_porta_up_once = data_word; v1 = v0; v4 = v3; v8 = v5; } player_host_channel->fine_porta_down_once = data_word; player_host_channel->porta_up = v0; player_host_channel->porta_down = v1; player_host_channel->fine_porta_up = v3; player_host_channel->fine_porta_down = v4; player_host_channel->porta_up_once = v5; player_host_channel->porta_down_once = v8; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { v0 = player_host_channel->tone_porta; v3 = player_host_channel->fine_tone_porta; v5 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = v1; v3 = v4; v5 = v8; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v3; player_host_channel->tone_porta_once = v5; player_host_channel->fine_tone_porta_once = data_word; } } EXECUTE_EFFECT(tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); - if ((!(player_channel->frequency)) || (tone_portamento_target_pitch <= player_channel->frequency)) { + if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->fine_tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = data_word; player_host_channel->fine_tone_porta = v0; player_host_channel->tone_porta_once = v1; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->tone_porta_once; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 16, 8-4, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->fine_tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = data_word; player_host_channel->fine_tone_porta_once = v3; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(fine_tone_portamento_once) { uint32_t tone_portamento_target_pitch; if (!data_word) data_word = player_host_channel->fine_tone_porta_once; if ((tone_portamento_target_pitch = player_host_channel->tone_porta_target_pitch)) { const AVSequencerTrack *track = player_host_channel->track; uint16_t v0, v1, v3; if (player_channel->host_channel == channel) { if (tone_portamento_target_pitch <= player_channel->frequency) { portamento_slide_down(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (tone_portamento_target_pitch >= player_channel->frequency) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } else { portamento_slide_up(avctx, player_host_channel, player_channel, data_word, 1, 8, channel); if (!player_channel->frequency || (tone_portamento_target_pitch <= player_channel->frequency)) { player_channel->frequency = tone_portamento_target_pitch; player_host_channel->tone_porta_target_pitch = 0; } } } v0 = player_host_channel->tone_porta; v1 = player_host_channel->fine_tone_porta; v3 = player_host_channel->tone_porta_once; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_SLIDES) { v0 = data_word; v1 = data_word; v3 = data_word; } player_host_channel->tone_porta = v0; player_host_channel->fine_tone_porta = v1; player_host_channel->tone_porta_once = v3; player_host_channel->fine_tone_porta_once = data_word; if (track->compat_flags & AVSEQ_TRACK_COMPAT_FLAG_TONE_PORTA) { player_host_channel->porta_up = data_word; player_host_channel->porta_down = data_word; player_host_channel->fine_porta_up = data_word; player_host_channel->fine_porta_down = data_word; player_host_channel->porta_up_once = data_word; player_host_channel->porta_down_once = data_word; player_host_channel->fine_porta_up_once = data_word; player_host_channel->fine_porta_down_once = data_word; } } } EXECUTE_EFFECT(note_slide) { uint16_t note_slide_value, note_slide_type; if (!(note_slide_value = (uint8_t) data_word)) note_slide_value = player_host_channel->note_slide; player_host_channel->note_slide = note_slide_value; if (!(note_slide_type = (data_word >> 8))) note_slide_type = player_host_channel->note_slide_type; player_host_channel->note_slide_type = note_slide_type; if (!(note_slide_type & 0x10)) note_slide_value = -note_slide_value; note_slide_value += player_host_channel->final_note; player_host_channel->final_note = note_slide_value; if (player_channel->host_channel == channel) player_channel->frequency = get_tone_pitch(avctx, player_host_channel, player_channel, note_slide_value); } EXECUTE_EFFECT(vibrato) { uint16_t vibrato_rate; int16_t vibrato_depth; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; vibrato_depth = (int8_t) data_word; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, vibrato_depth << 2); } EXECUTE_EFFECT(fine_vibrato) { uint16_t vibrato_rate; if (!(vibrato_rate = (data_word >> 8))) vibrato_rate = player_host_channel->vibrato_rate; player_host_channel->vibrato_rate = vibrato_rate; do_vibrato(avctx, player_host_channel, player_channel, channel, vibrato_rate, (int8_t) data_word); } EXECUTE_EFFECT(do_key_off) { if (data_word <= player_host_channel->tempo_counter) play_key_off(player_channel); } EXECUTE_EFFECT(hold_delay) { // TODO: Implement hold delay effect } EXECUTE_EFFECT(note_fade) { if (data_word <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } EXECUTE_EFFECT(note_cut) { if ((data_word & 0xFFF) <= player_host_channel->tempo_counter) { player_host_channel->effects_used[fx_byte >> 3] |= 1 << (7 - (fx_byte & 7)); if (player_channel->host_channel == channel) { player_channel->volume = 0; player_channel->sub_volume = 0; if (data_word & 0xF000) { player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_channel->mixer.flags = 0; } } } } EXECUTE_EFFECT(note_delay) { } EXECUTE_EFFECT(tremor) { uint8_t tremor_off, tremor_on; player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; if (!(tremor_off = (uint8_t) data_word)) tremor_off = player_host_channel->tremor_off_ticks; player_host_channel->tremor_off_ticks = tremor_off; if (!(tremor_on = (data_word >> 8))) tremor_on = player_host_channel->tremor_on_ticks; player_host_channel->tremor_on_ticks = tremor_on; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF)) tremor_off = tremor_on; if (tremor_off <= player_host_channel->tremor_count) { player_host_channel->flags ^= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF; player_host_channel->tremor_count = 0; } player_host_channel->tremor_count++; } EXECUTE_EFFECT(note_retrigger) { uint16_t retrigger_tick = data_word & 0x7FFF, retrigger_tick_count; if ((data_word & 0x8000) && data_word) retrigger_tick = player_host_channel->tempo / retrigger_tick; if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --retrigger_tick) { if (retrigger_tick <= retrigger_tick_count) retrigger_tick_count = -1; } else if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; } player_host_channel->retrig_tick_count = ++retrigger_tick_count; } EXECUTE_EFFECT(multi_retrigger_note) { uint8_t multi_retrigger_tick, multi_retrigger_volume_change; uint16_t retrigger_tick_count; uint32_t volume; if (!(multi_retrigger_tick = (data_word >> 8))) multi_retrigger_tick = player_host_channel->multi_retrig_tick; player_host_channel->multi_retrig_tick = multi_retrigger_tick; if (!(multi_retrigger_volume_change = (uint8_t) data_word)) multi_retrigger_volume_change = player_host_channel->multi_retrig_vol_chg; player_host_channel->multi_retrig_vol_chg = multi_retrigger_volume_change; if ((retrigger_tick_count = player_host_channel->retrig_tick_count) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE) || (player_channel->host_channel != channel)) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; } else if ((int8_t) multi_retrigger_volume_change < 0) { uint8_t multi_retrigger_scale = 4; if (!(avctx->player_song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_OLD_VOLUMES)) multi_retrigger_scale = player_host_channel->multi_retrig_scale; if ((int8_t) (multi_retrigger_volume_change -= 0xBF) >= 0) { volume = multi_retrigger_volume_change * multi_retrigger_scale; if (player_channel->volume >= volume) { player_channel->volume -= volume; } else { player_channel->volume = 0; player_channel->sub_volume = 0; } } else { volume = ((multi_retrigger_volume_change + 0x40) * multi_retrigger_scale) + player_channel->volume; if (volume < 0x100) { player_channel->volume = volume; } else { player_channel->volume = 0xFF; player_channel->sub_volume = 0xFF; } } } else { uint8_t volume_multiplier, volume_divider; volume = (player_channel->volume << 8); if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) volume += player_channel->sub_volume; if ((volume_multiplier = (multi_retrigger_volume_change >> 4))) volume *= volume_multiplier; if ((volume_divider = (multi_retrigger_volume_change & 0xF))) volume /= volume_divider; if (volume > 0xFFFF) volume = 0xFFFF; player_channel->volume = volume >> 8; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG) player_channel->sub_volume = volume; } if ((retrigger_tick_count = player_host_channel->retrig_tick_count) && --multi_retrigger_tick) { if (multi_retrigger_tick <= retrigger_tick_count) retrigger_tick_count = -1; } else if (player_channel->host_channel == channel) { player_channel->mixer.pos = 0; } player_host_channel->retrig_tick_count = ++retrigger_tick_count; } EXECUTE_EFFECT(extended_ctrl) { const AVSequencerModule *module; AVSequencerPlayerChannel *scan_player_channel; uint8_t extended_control_byte; uint16_t virtual_channel; const uint16_t extended_control_word = data_word & 0x0FFF; switch (data_word >> 12) { case 0 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; if (!extended_control_word) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ; break; case 1 : player_host_channel->glissando = extended_control_word; break; case 2 : extended_control_byte = extended_control_word; switch (extended_control_word >> 8) { case 0 : if (!extended_control_byte) extended_control_byte = 1; if (extended_control_byte > 4) extended_control_byte = 4; player_host_channel->multi_retrig_scale = extended_control_byte; break; case 1 : player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; if (extended_control_byte) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SUB_SLIDE_RETRIG; break; case 2 : if (extended_control_byte) player_host_channel->multi_retrig_tick = player_host_channel->tempo / extended_control_byte; break; } break; case 3 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->mixer.flags = 0; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 4 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) scan_player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; scan_player_channel++; } while (++virtual_channel < module->channels); break; case 5 : module = avctx->player_module; scan_player_channel = avctx->player_channel; virtual_channel = 0; do { if ((scan_player_channel->host_channel == channel) && (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) play_key_off(scan_player_channel); scan_player_channel++; } while (++virtual_channel < module->channels); break; case 6 : player_host_channel->sub_slide = extended_control_word; break; } } EXECUTE_EFFECT(invert_loop) @@ -7288,1041 +7288,1041 @@ EXECUTE_SYNTH_CODE_INSTRUCTION(setrans) return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setnote) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency; uint16_t octave; int16_t note; int8_t finetune; instruction_data += player_channel->variable[src_var]; octave = (int16_t) instruction_data / 12; note = (int16_t) instruction_data % 12; if (note < 0) { octave--; note += 12; } if ((finetune = player_channel->finetune) < 0) { finetune += -0x80; note--; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (int32_t) (finetune * (int16_t) next_frequency) >> 7; if ((int16_t) (octave -= 4) < 0) { octave = -octave; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> (16 + octave); } else { frequency <<= octave; player_channel->frequency = ((uint64_t) frequency * player_channel->sample->rate) >> 16; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setptch) { uint32_t frequency = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) frequency += player_channel->variable[dst_var]; else frequency += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; player_channel->frequency = frequency; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(setper) { uint32_t period = instruction_data + player_channel->variable[src_var]; if (dst_var == 15) period += player_channel->variable[dst_var]; else period += (player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; if (period) player_channel->frequency = AVSEQ_SLIDE_CONST / period; else player_channel->frequency = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(reset) { instruction_data += player_channel->variable[src_var]; if (!(instruction_data & 0x01)) player_channel->arpeggio_slide = 0; if (!(instruction_data & 0x02)) player_channel->vibrato_slide = 0; if (!(instruction_data & 0x04)) player_channel->tremolo_slide = 0; if (!(instruction_data & 0x08)) player_channel->pannolo_slide = 0; if (!(instruction_data & 0x10)) { AVSequencerPlayerHostChannel *const player_host_channel = avctx->player_host_channel + player_channel->host_channel; int32_t portamento_value = player_channel->portamento; if (portamento_value < 0) { portamento_value = -portamento_value; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) linear_slide_down(avctx, player_channel, player_channel->frequency, portamento_value); else amiga_slide_down(player_channel, player_channel->frequency, portamento_value); } else if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_LINEAR_FREQ) { linear_slide_up(avctx, player_channel, player_channel->frequency, portamento_value); } else { amiga_slide_up(player_channel, player_channel->frequency, portamento_value); } } if (!(instruction_data & 0x20)) player_channel->portamento = 0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volslup) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_up; player_channel->vol_sl_up = instruction_data; if ((slide_volume += instruction_data) < instruction_data) slide_volume = 0xFFFF; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(volsldn) { uint16_t slide_volume = (player_channel->volume << 8) + player_channel->sub_volume; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->vol_sl_dn; player_channel->vol_sl_dn = instruction_data; if (slide_volume < instruction_data) instruction_data = slide_volume; slide_volume -= instruction_data; player_channel->volume = slide_volume >> 8; player_channel->sub_volume = slide_volume; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmspd) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmdpth) { instruction_data += player_channel->variable[src_var]; player_channel->tremolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->tremolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->tremolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->tremolo_waveform)) player_channel->tremolo_pos = instruction_data % waveform->samples; else player_channel->tremolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(tremolo) { const AVSequencerSynthWave *waveform; uint16_t tremolo_rate; int16_t tremolo_depth; instruction_data += player_channel->variable[src_var]; if (!(tremolo_rate = (instruction_data >> 8))) tremolo_rate = player_channel->tremolo_rate; player_channel->tremolo_rate = tremolo_rate; tremolo_depth = (instruction_data & 0xFF) << 2; if (!tremolo_depth) tremolo_depth = player_channel->tremolo_depth; player_channel->tremolo_depth = tremolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t tremolo_slide_value; waveform_pos = player_channel->tremolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) tremolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else tremolo_slide_value = waveform->data[waveform_pos]; tremolo_slide_value *= -tremolo_depth; tremolo_slide_value >>= 7 - 2; player_channel->tremolo_pos = (waveform_pos + tremolo_rate) % waveform->samples; se_tremolo_do(avctx, player_channel, tremolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(trmval) { int32_t tremolo_slide_value; instruction_data += player_channel->variable[src_var]; tremolo_slide_value = (int16_t) instruction_data; se_tremolo_do(avctx, player_channel, tremolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panleft) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_left; player_channel->pan_sl_left = instruction_data; if (panning < instruction_data) instruction_data = panning; panning -= instruction_data; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panrght) { uint16_t panning = ((uint8_t) player_channel->panning << 8) + player_channel->sub_panning; if (!(instruction_data += player_channel->variable[src_var])) instruction_data = player_channel->pan_sl_right; player_channel->pan_sl_right = instruction_data; if ((panning += instruction_data) < instruction_data) panning = 0xFFFF; player_channel->panning = panning >> 8; player_channel->sub_panning = panning; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panspd) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_rate = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pandpth) { instruction_data += player_channel->variable[src_var]; player_channel->pannolo_depth = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwave) { AVSequencerSynthWave *const *waveform_list = player_channel->waveform_list; uint32_t waveform_num = -1; instruction_data += player_channel->variable[src_var]; player_channel->pannolo_waveform = NULL; while ((++waveform_num < player_channel->synth->waveforms) && waveform_list[waveform_num]) { if (waveform_num == instruction_data) { player_channel->pannolo_waveform = waveform_list[waveform_num]; break; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panwavp) { const AVSequencerSynthWave *waveform; instruction_data += player_channel->variable[src_var]; if ((waveform = player_channel->pannolo_waveform)) player_channel->pannolo_pos = instruction_data % waveform->samples; else player_channel->pannolo_pos = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(pannolo) { const AVSequencerSynthWave *waveform; uint16_t pannolo_rate; int16_t pannolo_depth; instruction_data += player_channel->variable[src_var]; if (!(pannolo_rate = (instruction_data >> 8))) pannolo_rate = player_channel->pannolo_rate; player_channel->pannolo_rate = pannolo_rate; pannolo_depth = (instruction_data & 0xFF) << 2; if (!pannolo_depth) pannolo_depth = player_channel->pannolo_depth; player_channel->pannolo_depth = pannolo_depth; if ((waveform = player_channel->vibrato_waveform)) { uint32_t waveform_pos; int32_t pannolo_slide_value; waveform_pos = player_channel->pannolo_pos % waveform->samples; if (waveform->flags & AVSEQ_SYNTH_WAVE_FLAG_8BIT) pannolo_slide_value = ((int8_t *) waveform->data)[waveform_pos] << 8; else pannolo_slide_value = waveform->data[waveform_pos]; pannolo_slide_value *= -pannolo_depth; pannolo_slide_value >>= 7 - 2; player_channel->pannolo_pos = (waveform_pos + pannolo_rate) % waveform->samples; se_pannolo_do(avctx, player_channel, pannolo_slide_value); } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(panval) { int32_t pannolo_slide_value; instruction_data += player_channel->variable[src_var]; pannolo_slide_value = (int16_t) instruction_data; se_pannolo_do(avctx, player_channel, pannolo_slide_value); return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(nop) { return synth_code_line; } static void process_row(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { uint32_t current_tick; AVSequencerSong *song = avctx->player_song; uint16_t counted = 0; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC; current_tick = player_host_channel->tempo_counter; current_tick++; if (current_tick >= ((uint32_t) player_host_channel->fine_pattern_delay + player_host_channel->tempo)) current_tick = 0; if (!(player_host_channel->tempo_counter = current_tick)) { const AVSequencerTrack *track; const AVSequencerOrderList *const order_list = song->order_list + channel; AVSequencerOrderData *order_data; const AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; uint16_t pattern_delay, row, last_row, track_length; uint32_t ord = -1; if (player_channel->host_channel == channel) { const uint32_t slide_value = player_host_channel->arpeggio_freq; player_host_channel->arpeggio_freq = 0; player_channel->frequency += slide_value; } player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO); AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); player_host_channel->effect = NULL; player_host_channel->arpeggio_tick = 0; player_host_channel->note_delay = 0; player_host_channel->retrig_tick_count = 0; if ((pattern_delay = player_host_channel->pattern_delay) && (pattern_delay > player_host_channel->pattern_delay_count++)) return; player_host_channel->pattern_delay_count = 0; player_host_channel->pattern_delay = 0; row = player_host_channel->row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP; order_data = player_host_channel->order; track = player_host_channel->track; goto loop_to_row; } player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP_JMP; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHG_PATTERN; order_data = player_host_channel->order; if ((player_host_channel->chg_pattern < song->tracks) && ((track = song->track_list[player_host_channel->chg_pattern]))) { if (!(avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN)) player_host_channel->track = track; goto loop_to_row; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) goto get_new_pattern; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) { if (!row--) goto get_new_pattern; } else if (++row >= player_host_channel->max_row) { get_new_pattern: order_data = player_host_channel->order; if (avctx->player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_PATTERN) { track = player_host_channel->track; goto loop_to_row; } ord = -1; if (order_data) { while (++ord < order_list->orders) { if (order_data == order_list->order_data[ord]) break; } } check_next_empty_order: do { ord++; if ((ord >= order_list->orders) || (!(order_data = order_list->order_data[ord]))) { song_end_found: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if ((order_list->rep_start >= order_list->orders) || (!(order_data = order_list->order_data[order_list->rep_start]))) { disable_channel: player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; player_host_channel->tempo = 0; return; } if (order_data->flags & (AVSEQ_ORDER_DATA_FLAG_END_ORDER|AVSEQ_ORDER_DATA_FLAG_END_SONG)) goto disable_channel; row = 0; - if (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || ((!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE)) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT))) + if (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT))) goto disable_channel; if ((track = order_data->track)) break; } if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_ORDER) goto song_end_found; if (order_data->flags & AVSEQ_ORDER_DATA_FLAG_END_SONG) { if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) goto disable_channel; goto song_end_found; } - } while (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || ((!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE)) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT)) || (!(track = order_data->track))); + } while (((player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_ONCE)) || (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) && (order_data->flags & AVSEQ_ORDER_DATA_FLAG_NOT_IN_REPEAT)) || (!(track = order_data->track))); player_host_channel->order = order_data; player_host_channel->track = track; if (player_host_channel->gosub_depth < order_data->played) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) player_host_channel->tempo = 0; } order_data->played++; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_RESET; loop_to_row: track_length = track->last_row; row = order_data->first_row; last_row = order_data->last_row; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK) { player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; row = player_host_channel->break_row; if (track_length < row) row = order_data->first_row; } if (track_length < row) goto check_next_empty_order; if (track_length < last_row) last_row = track_length; player_host_channel->max_row = last_row + 1; if ((pattern_delay = order_data->tempo)) player_host_channel->tempo = pattern_delay; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_BACKWARDS) row = last_row - row; } player_host_channel->row = row; if ((int) ((player_host_channel->track->data) + row)->note == AVSEQ_TRACK_DATA_NOTE_END) { if (++counted) goto get_new_pattern; goto disable_channel; } } } static const AVSequencerPlayerEffects fx_lut[128] = { {arpeggio, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_up, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_portamento_down, NULL, check_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_up_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {fine_portamento_down_once, NULL, check_portamento, 0x00, 0x01, 0x0000}, {tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_tone_portamento, preset_tone_portamento, check_tone_portamento, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {fine_tone_portamento_once, preset_tone_portamento, check_tone_portamento, 0x00, 0x00, 0x0000}, {note_slide, NULL, check_note_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_vibrato, preset_vibrato, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {fine_vibrato, preset_vibrato, NULL, 0x00, 0x01, 0x0000}, {do_key_off, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {hold_delay, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_fade, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_cut, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_delay, preset_note_delay, NULL, 0x00, 0x00, 0x0000}, {tremor, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {note_retrigger, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {multi_retrigger_note, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {extended_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {invert_loop, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {exec_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {stop_fx, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {volume_slide_up, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {volume_slide_down, NULL, check_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_volume_slide_up, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {fine_volume_slide_down, NULL, check_volume_slide, 0x00, 0x01, 0x0000}, {volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {tremolo, preset_tremolo, NULL, 0x00, 0x01, 0x0000}, {set_track_volume, NULL, NULL, 0x00, 0x01, 0x0000}, {track_volume_slide_up, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_volume_slide_down, NULL, check_track_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_volume_slide_up, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {fine_track_volume_slide_down, NULL, check_track_volume_slide, 0x00, 0x01, 0x0000}, {track_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_tremolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {panning_slide_left, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {panning_slide_right, NULL, check_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_panning_slide_left, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {fine_panning_slide_right, NULL, check_panning_slide, 0x00, 0x01, 0x0000}, {panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_track_panning, NULL, NULL, 0x00, 0x01, 0x0000}, {track_panning_slide_left, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_panning_slide_right, NULL, check_track_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {fine_track_panning_slide_left, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {fine_track_panning_slide_right, NULL, check_track_panning_slide, 0x00, 0x01, 0x0000}, {track_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {track_pannolo, NULL, NULL, 0x00, 0x01, 0x0000}, {set_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {set_relative_tempo, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_break, NULL, NULL, 0x00, 0x02, 0x0000}, {position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {relative_position_jump, NULL, NULL, 0x00, 0x02, 0x0000}, {change_pattern, NULL, NULL, 0x00, 0x02, 0x0000}, {reverse_pattern_play, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {fine_pattern_delay, NULL, NULL, 0x00, 0x02, 0x0000}, {pattern_loop, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub, NULL, NULL, 0x00, 0x02, 0x0000}, {gosub_return, NULL, NULL, 0x00, 0x02, 0x0000}, {channel_sync, NULL, NULL, 0x00, 0x02, 0x0000}, {set_sub_slides, NULL, NULL, 0x00, 0x02, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {sample_offset_high, NULL, NULL, 0x00, 0x01, 0x0000}, {sample_offset_low, NULL, NULL, 0x00, 0x01, 0x0000}, {set_hold, NULL, NULL, 0x00, 0x01, 0x0000}, {set_decay, NULL, NULL, 0x00, 0x01, 0x0000}, {set_transpose, preset_set_transpose, NULL, 0x00, 0x01, 0x0000}, {instrument_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {instrument_change, NULL, NULL, 0x00, 0x01, 0x0000}, {synth_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_synth_value, NULL, NULL, 0x00, 0x01, 0x0000}, {envelope_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {set_envelope_value, NULL, NULL, 0x00, 0x01, 0x0000}, {nna_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {loop_ctrl, NULL, NULL, 0x00, 0x01, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {set_speed, NULL, NULL, 0x00, 0x00, 0x0000}, {speed_slide_faster, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {speed_slide_slower, NULL, check_speed_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_speed_slide_faster, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {fine_speed_slide_slower, NULL, check_speed_slide, 0x00, 0x00, 0x0000}, {speed_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0001}, {spenolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {spenolo, NULL, NULL, 0x00, 0x00, 0x0000}, {channel_ctrl, NULL, check_channel_control, 0x00, 0x00, 0x0000}, {set_global_volume, NULL, NULL, 0x00, 0x00, 0x0000}, {global_volume_slide_up, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_volume_slide_down, NULL, check_global_volume_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_volume_slide_up, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {fine_global_volume_slide_down, NULL, check_global_volume_slide, 0x00, 0x00, 0x0000}, {global_volume_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_tremolo, NULL, NULL, 0x00, 0x00, 0x0000}, {set_global_panning, NULL, NULL, 0x00, 0x00, 0x0000}, {global_panning_slide_left, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_panning_slide_right, NULL, check_global_panning_slide, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {fine_global_panning_slide_left, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {fine_global_panning_slide_right, NULL, check_global_panning_slide, 0x00, 0x00, 0x0000}, {global_panning_slide_to, NULL, check_volume_slide_to, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x01, 0x0000}, {global_pannolo, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0001}, {global_pannolo, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {NULL, NULL, NULL, 0x00, 0x00, 0x0000}, {user_sync, NULL, NULL, AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW, 0x00, 0x0000} }; static void get_effects(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerTrack *track; const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *track_data; uint32_t fx = -1; if (!(track = player_host_channel->track)) return; track_data = track->data + player_host_channel->row; if ((track_fx = player_host_channel->effect)) { while (++fx < track_data->effects) { if (track_fx == track_data->effects_data[fx]) break; } } else if (track_data->effects) { fx = 0; track_fx = track_data->effects_data[0]; } else { track_fx = NULL; } player_host_channel->effect = track_fx; if ((fx < track_data->effects) && track_data->effects_data[fx]) { do { const int fx_byte = track_fx->command & 0x7F; if (fx_byte == AVSEQ_TRACK_EFFECT_CMD_EXECUTE_FX) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX; player_host_channel->exec_fx = track_fx->data; if (player_host_channel->tempo_counter < player_host_channel->exec_fx) break; } } while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))); if (player_host_channel->effect != track_fx) { player_host_channel->effect = track_fx; AV_WN64A(player_host_channel->effects_used, 0); AV_WN64A(player_host_channel->effects_used + 8, 0); } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*pre_fx_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t data_word); const int fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; if ((pre_fx_func = effects_lut->pre_pattern_func)) pre_fx_func(avctx, player_host_channel, player_channel, channel, track_fx->data); } } } static void run_effects(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel) { const AVSequencerSong *const song = avctx->player_song; const AVSequencerTrack *track; if ((track = player_host_channel->track) && player_host_channel->effect) { const AVSequencerTrackEffect *track_fx; const AVSequencerTrackRow *const track_data = track->data + player_host_channel->row; uint32_t fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (flags != player_host_channel->tempo_counter) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } fx = -1; while ((++fx < track_data->effects) && ((track_fx = track_data->effects_data[fx]))) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; uint8_t channel_ctrl_type; fx_byte = track_fx->command & 0x7F; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = track_fx->data; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!(flags & AVSEQ_PLAYER_EFFECTS_FLAG_EXEC_WHOLE_ROW)) continue; flags = player_host_channel->exec_fx; if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_EXEC_FX)) flags = effects_lut->std_exec_tick; if (player_host_channel->tempo_counter < flags) continue; if (player_host_channel->effects_used[(fx_byte >> 3)] & (1 << (7 - (fx_byte & 7)))) continue; effects_lut->effect_func(avctx, player_host_channel, player_channel, channel, fx_byte, data_word); if ((channel_ctrl_type = player_host_channel->ch_control_type)) { if (player_host_channel->ch_control_affect & effects_lut->and_mask_ctrl) { AVSequencerPlayerHostChannel *new_player_host_channel; AVSequencerPlayerChannel *new_player_channel; uint16_t ctrl_fx_byte, ctrl_data_word, ctrl_flags, ctrl_channel; switch (channel_ctrl_type) { case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_NORMAL : if ((ctrl_channel = player_host_channel->ch_control_channel) != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } break; case AVSEQ_PLAYER_HOST_CHANNEL_CH_CONTROL_TYPE_MULTIPLE : ctrl_channel = 0; do { if ((ctrl_channel != channel) && (player_host_channel->control_channels[(ctrl_channel >> 3)] & (1 << (7 - (ctrl_channel & 7))))) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; default : ctrl_channel = 0; do { if (ctrl_channel != channel) { new_player_host_channel = avctx->player_host_channel + ctrl_channel; new_player_channel = avctx->player_channel + new_player_host_channel->virtual_channel; ctrl_fx_byte = fx_byte; ctrl_data_word = data_word; ctrl_flags = flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, channel, &ctrl_fx_byte, &ctrl_data_word, &ctrl_flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + ctrl_fx_byte; } if (new_player_host_channel->effects_used[(ctrl_fx_byte >> 3)] & (1 << (7 - (ctrl_fx_byte & 7)))) continue; effects_lut->effect_func(avctx, new_player_host_channel, new_player_channel, ctrl_channel, ctrl_fx_byte, ctrl_data_word); } } while (++ctrl_channel < song->channels); break; } } } if (player_host_channel->effect == track_fx) break; } } } static int16_t get_key_table(const AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, uint16_t note) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerKeyboard *keyboard; const AVSequencerSample *sample; uint16_t smp = 1, i; int8_t transpose = 0; if (!player_host_channel->instrument) player_host_channel->nna = instrument->nna; player_host_channel->instr_note = note; player_host_channel->sample_note = note; player_host_channel->instrument = instrument; @@ -8475,1593 +8475,1593 @@ previous_nna_found: if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } } scan_player_channel++; } while (++nna_channel < module->channels); find_nna: scan_player_channel = avctx->player_channel; new_player_channel = NULL; nna_channel = 0; do { if (!((scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) || (scan_player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY))) { *virtual_channel = nna_channel; new_player_channel = scan_player_channel; goto nna_found; } scan_player_channel++; } while (++nna_channel < module->channels); nna_max_volume = 256; scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) { nna_volume = player_channel->final_volume; if (nna_max_volume > nna_volume) { nna_max_volume = nna_volume; *virtual_channel = nna_channel; new_player_channel = scan_player_channel; break; } } scan_player_channel++; } while (++nna_channel < module->channels); if (!new_player_channel) new_player_channel = player_channel; nna_found: if (player_host_channel->dct && (new_player_channel != player_channel)) { scan_player_channel = avctx->player_channel; nna_channel = 0; do { if (scan_player_channel->host_channel == channel) { if (trigger_dct(player_host_channel, scan_player_channel, player_host_channel->dct)) { if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_VOLUME_DNA) scan_player_channel->entry_pos[0] = scan_player_channel->dna_pos[0]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_PANNING_DNA) scan_player_channel->entry_pos[1] = scan_player_channel->dna_pos[1]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SLIDE_DNA) scan_player_channel->entry_pos[2] = scan_player_channel->dna_pos[2]; if (scan_player_channel->use_nna_flags & AVSEQ_PLAYER_CHANNEL_USE_NNA_FLAG_SPECIAL_DNA) scan_player_channel->entry_pos[3] = scan_player_channel->dna_pos[3]; switch (player_host_channel->dna) { case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_CUT : player_channel->mixer.flags = 0; break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_OFF : play_key_off(scan_player_channel); break; case AVSEQ_PLAYER_HOST_CHANNEL_DNA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } } scan_player_channel++; } while (++nna_channel < module->channels); } player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; return new_player_channel; } static AVSequencerPlayerChannel *play_note_got(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, uint16_t note, const uint16_t channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; uint32_t note_swing, pitch_swing, frequency = 0; uint32_t seed; uint16_t virtual_channel; player_host_channel->dct = instrument->dct; player_host_channel->dna = instrument->dna; note_swing = (instrument->note_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; note_swing = ((uint64_t) seed * note_swing) >> 32; note_swing -= instrument->note_swing; note += note_swing; player_host_channel->final_note = note; player_host_channel->finetune = sample->finetune; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_TRANSPOSE) player_host_channel->finetune = player_host_channel->trans_finetune; player_host_channel->prev_volume_env = player_channel->vol_env.envelope; player_host_channel->prev_panning_env = player_channel->pan_env.envelope; player_host_channel->prev_slide_env = player_channel->slide_env.envelope; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_host_channel->prev_resonance_env = player_channel->resonance_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *const) &virtual_channel); player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_channel->instrument = player_host_channel->instrument; player_channel->sample = player_host_channel->sample; player_channel->instr_note = player_host_channel->instr_note; player_channel->sample_note = player_host_channel->sample_note; if (player_channel->instr_note || player_channel->sample_note) { const int16_t final_note = player_host_channel->final_note; player_channel->final_note = final_note; frequency = get_tone_pitch(avctx, player_host_channel, player_channel, final_note); } note_swing = pitch_swing = ((uint64_t) frequency * instrument->pitch_swing) >> 16; pitch_swing <<= 1; if (pitch_swing < note_swing) pitch_swing = 0xFFFFFFFE; note_swing = pitch_swing++ >> 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; pitch_swing = ((uint64_t) seed * pitch_swing) >> 32; pitch_swing -= note_swing; if ((int32_t) (frequency += pitch_swing) < 0) frequency = 0; player_channel->frequency = frequency; return player_channel; } static AVSequencerPlayerChannel *play_note(AVSequencerContext *const avctx, const AVSequencerInstrument *const instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t octave, uint16_t note, const uint16_t channel) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_RETRIG_NOTE; if ((note = get_key_table_note(avctx, instrument, player_host_channel, octave, note)) == 0x8000) return NULL; return play_note_got(avctx, player_host_channel, player_channel, note, channel); } static const void *assign_envelope_lut[] = { assign_volume_envelope, assign_panning_envelope, assign_slide_envelope, assign_vibrato_envelope, assign_tremolo_envelope, assign_pannolo_envelope, assign_channolo_envelope, assign_spenolo_envelope, assign_track_tremolo_envelope, assign_track_pannolo_envelope, assign_global_tremolo_envelope, assign_global_pannolo_envelope, assign_resonance_envelope }; static const void *assign_auto_envelope_lut[] = { assign_auto_vibrato_envelope, assign_auto_tremolo_envelope, assign_auto_pannolo_envelope }; static void init_new_instrument(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerInstrument *const instrument = player_host_channel->instrument; const AVSequencerSample *const sample = player_host_channel->sample; AVSequencerPlayerGlobals *player_globals; const AVSequencerEnvelope * (**assign_envelope)(const AVSequencerContext *const avctx, const AVSequencerInstrument *instrument, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const AVSequencerEnvelope **envelope, AVSequencerPlayerEnvelope **player_envelope); const AVSequencerEnvelope * (**assign_auto_envelope)(const AVSequencerSample *sample, AVSequencerPlayerChannel *const player_channel, AVSequencerPlayerEnvelope **player_envelope); uint32_t volume = 0, panning, i; if (instrument) { uint32_t volume_swing, abs_volume_swing, seed; volume = sample->global_volume * instrument->global_volume; volume_swing = (volume * instrument->volume_swing) >> 8; abs_volume_swing = (volume_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; abs_volume_swing = ((uint64_t) seed * abs_volume_swing) >> 32; abs_volume_swing -= volume_swing; if ((int32_t) (volume += abs_volume_swing) < 0) volume = 0; if (volume > (255*255)) volume = 255*255; } else { volume = sample->global_volume * 255; } player_channel->instr_volume = volume; player_globals = avctx->player_globals; player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; if (instrument) { player_channel->fade_out = instrument->fade_out; player_channel->fade_out_count = 65535; player_host_channel->nna = instrument->nna; } player_channel->auto_vibrato_sweep = sample->vibrato_sweep; player_channel->auto_tremolo_sweep = sample->tremolo_sweep; player_channel->auto_pan_sweep = sample->pannolo_sweep; player_channel->auto_vibrato_depth = sample->vibrato_depth; player_channel->auto_vibrato_rate = sample->vibrato_rate; player_channel->auto_tremolo_depth = sample->tremolo_depth; player_channel->auto_tremolo_rate = sample->tremolo_rate; player_channel->auto_pan_depth = sample->pannolo_depth; player_channel->auto_pan_rate = sample->pannolo_rate; player_channel->auto_vibrato_count = 0; player_channel->auto_tremolo_count = 0; player_channel->auto_pannolo_count = 0; player_channel->auto_vibrato_freq = 0; player_channel->auto_tremolo_vol = 0; player_channel->auto_pannolo_pan = 0; player_channel->slide_env_freq = 0; player_channel->flags &= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; player_host_channel->arpeggio_freq = 0; player_host_channel->vibrato_slide = 0; player_host_channel->tremolo_slide = 0; if (sample->env_proc_flags & AVSEQ_SAMPLE_FLAG_PROC_LINEAR_AUTO_VIB) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB; if (instrument) { if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_PORTA_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_LINEAR_SLIDE_ENV) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV; } assign_envelope = (void *) &assign_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; if (instrument) { if (assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope) && (instrument->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (instrument->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (instrument->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (instrument->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; if (instrument->env_rnd_delay_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RND_DELAY; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } else { assign_envelope[i](avctx, instrument, player_host_channel, player_channel, &envelope, &player_envelope); player_envelope->envelope = NULL; player_channel->vol_env.value = 0; } } while (++i < (sizeof (assign_envelope_lut) / sizeof (void *))); player_channel->vol_env.value = -1; assign_auto_envelope = (void *) &assign_auto_envelope_lut; i = 0; do { const AVSequencerEnvelope *envelope; AVSequencerPlayerEnvelope *player_envelope; const uint16_t mask = 1 << i; envelope = assign_auto_envelope[i](sample, player_channel, &player_envelope); if (player_envelope->envelope && (sample->env_usage_flags & mask)) continue; if ((player_envelope->envelope = envelope)) { uint8_t flags = 0; uint16_t envelope_pos = 0, envelope_value = 0; if (sample->env_proc_flags & mask) flags = AVSEQ_PLAYER_ENVELOPE_FLAG_FIRST_ADD; if (sample->env_retrig_flags & mask) { flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_NO_RETRIG; envelope_pos = player_envelope->pos; envelope_value = player_envelope->value; } if (sample->env_random_flags & mask) flags |= AVSEQ_PLAYER_ENVELOPE_FLAG_RANDOM; player_envelope->value = envelope_value; player_envelope->tempo = envelope->tempo; player_envelope->tempo_count = 0; player_envelope->sustain_counted = 0; player_envelope->loop_counted = 0; player_envelope->sustain_start = envelope->sustain_start; player_envelope->sustain_end = envelope->sustain_end; player_envelope->sustain_count = envelope->sustain_count; player_envelope->loop_start = envelope->loop_start; player_envelope->loop_end = envelope->loop_end; player_envelope->loop_count = envelope->loop_count; player_envelope->value_min = envelope->value_min; player_envelope->value_max = envelope->value_max; player_envelope->rep_flags = envelope->flags; set_envelope(player_channel, player_envelope, envelope_pos); player_envelope->flags |= flags; } } while (++i < (sizeof (assign_auto_envelope_lut) / sizeof (void *))); panning = (uint8_t) player_host_channel->track_note_panning; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN; if (sample->flags & AVSEQ_SAMPLE_FLAG_SAMPLE_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (sample->flags & AVSEQ_SAMPLE_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = sample->panning; player_channel->sub_panning = sample->sub_panning; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->track_note_panning = panning; player_host_channel->track_note_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } else { player_channel->panning = player_host_channel->track_panning; player_channel->sub_panning = player_host_channel->track_sub_panning; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; } player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument) { uint32_t panning_swing, seed; int32_t panning_separation; if ((instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) && (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_AFFECT_CHANNEL_PAN)) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN; if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_DEFAULT_PANNING) { player_channel->flags &= ~(AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN|AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN); if (instrument->flags & AVSEQ_INSTRUMENT_FLAG_SURROUND_PANNING) player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN; player_channel->panning = instrument->default_panning; player_channel->sub_panning = instrument->default_sub_pan; player_host_channel->pannolo_slide = 0; panning = (uint8_t) player_channel->panning; if (instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_AFFECT_CHANNEL_PAN) { player_host_channel->track_panning = player_channel->panning; player_host_channel->track_sub_panning = player_channel->sub_panning; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN; } } panning_separation = (((int16_t) player_host_channel->instr_note - ((uint8_t) instrument->pitch_pan_center + 1)) * instrument->pitch_pan_separation) >> 8; panning_swing = (instrument->panning_swing << 1) + 1; avctx->seed = seed = ((int32_t) avctx->seed * AVSEQ_RANDOM_CONST) + 1; panning_swing = ((uint64_t) seed * panning_swing) >> 32; panning_swing -= instrument->panning_swing; panning += panning_swing; if ((int32_t) (panning += panning_separation) < 0) panning = 0; if (panning > 255) panning = 255; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) player_host_channel->track_panning = panning; else player_channel->panning = panning; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_AFFECT_CHAN_PAN) { player_host_channel->track_panning = panning; player_channel->panning = panning; } } } static void init_new_sample(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel) { const AVSequencerSample *const sample = player_host_channel->sample; const AVSequencerSynth *synth; AVMixerData *mixer; uint32_t samples; if ((samples = sample->samples)) { uint8_t flags, repeat_mode, playback_flags; player_channel->mixer.len = samples; player_channel->mixer.data = sample->data; player_channel->mixer.rate = player_channel->frequency; flags = sample->flags; if (flags & AVSEQ_SAMPLE_FLAG_SUSTAIN_LOOP) { player_channel->mixer.repeat_start = sample->sustain_repeat; player_channel->mixer.repeat_length = sample->sustain_rep_len; player_channel->mixer.repeat_count = sample->sustain_rep_count; repeat_mode = sample->sustain_repeat_mode; flags >>= 1; } else { player_channel->mixer.repeat_start = sample->repeat; player_channel->mixer.repeat_length = sample->rep_len; player_channel->mixer.repeat_count = sample->rep_count; repeat_mode = sample->repeat_mode; } player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = sample->bits_per_sample; playback_flags = AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (sample->flags & AVSEQ_SAMPLE_FLAG_REVERSE) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; if ((flags & AVSEQ_SAMPLE_FLAG_LOOP) && player_channel->mixer.repeat_length) { playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_LOOP; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_PINGPONG) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG; if (repeat_mode & AVSEQ_SAMPLE_REP_MODE_BACKWARDS) playback_flags |= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; } player_channel->mixer.flags = playback_flags; } - if ((!(synth = sample->synth)) || (!player_host_channel->synth) || (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE))) + if (!(synth = sample->synth) || !player_host_channel->synth || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_CODE)) player_host_channel->synth = synth; if ((player_channel->synth = player_host_channel->synth)) { const uint16_t *src_var; uint16_t *dst_var; uint16_t keep_flags, i; player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_PLAY; - if ((!(player_host_channel->waveform_list)) || (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS))) { + if (!player_host_channel->waveform_list || !(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_WAVEFORMS)) { AVSequencerSynthWave *const *waveform_list = synth->waveform_list; const AVSequencerSynthWave *waveform = NULL; player_host_channel->waveform_list = waveform_list; player_host_channel->waveforms = synth->waveforms; if (synth->waveforms) waveform = waveform_list[0]; player_channel->vibrato_waveform = waveform; player_channel->tremolo_waveform = waveform; player_channel->pannolo_waveform = waveform; player_channel->arpeggio_waveform = waveform; } player_channel->waveform_list = player_host_channel->waveform_list; player_channel->waveforms = player_host_channel->waveforms; keep_flags = synth->pos_keep_mask; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_VOLUME)) player_host_channel->entry_pos[0] = synth->entry_pos[0]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_PANNING)) player_host_channel->entry_pos[1] = synth->entry_pos[1]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SLIDE)) player_host_channel->entry_pos[2] = synth->entry_pos[2]; if (!(synth->pos_keep_mask & AVSEQ_SYNTH_POS_KEEP_MASK_SPECIAL)) player_host_channel->entry_pos[3] = synth->entry_pos[3]; player_channel->use_sustain_flags = synth->use_sustain_flags; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_VOLUME_KEEP)) player_host_channel->sustain_pos[0] = synth->sustain_pos[0]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_PANNING_KEEP)) player_host_channel->sustain_pos[1] = synth->sustain_pos[1]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SLIDE_KEEP)) player_host_channel->sustain_pos[2] = synth->sustain_pos[2]; if (!(player_channel->use_sustain_flags & AVSEQ_SYNTH_USE_SUSTAIN_FLAG_SPECIAL_KEEP)) player_host_channel->sustain_pos[3] = synth->sustain_pos[3]; player_channel->use_nna_flags = synth->use_nna_flags; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_NNA)) player_host_channel->nna_pos[0] = synth->nna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_NNA)) player_host_channel->nna_pos[1] = synth->nna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_NNA)) player_host_channel->nna_pos[2] = synth->nna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_NNA)) player_host_channel->nna_pos[3] = synth->nna_pos[3]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_VOLUME_DNA)) player_host_channel->dna_pos[0] = synth->dna_pos[0]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_PANNING_DNA)) player_host_channel->dna_pos[1] = synth->dna_pos[1]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SLIDE_DNA)) player_host_channel->dna_pos[2] = synth->dna_pos[2]; if (!(synth->nna_pos_keep_mask & AVSEQ_SYNTH_NNA_POS_KEEP_MASK_SPECIAL_DNA)) player_host_channel->dna_pos[3] = synth->dna_pos[3]; keep_flags = 1; src_var = (const uint16_t *) &(synth->variable[0]); dst_var = (uint16_t *) &(player_host_channel->variable[0]); i = 16; do { if (!(synth->var_keep_mask & keep_flags)) *dst_var = *src_var; keep_flags <<= 1; src_var++; dst_var++; } while (--i); player_channel->entry_pos[0] = player_host_channel->entry_pos[0]; player_channel->entry_pos[1] = player_host_channel->entry_pos[1]; player_channel->entry_pos[2] = player_host_channel->entry_pos[2]; player_channel->entry_pos[3] = player_host_channel->entry_pos[3]; player_channel->sustain_pos[0] = player_host_channel->sustain_pos[0]; player_channel->sustain_pos[1] = player_host_channel->sustain_pos[1]; player_channel->sustain_pos[2] = player_host_channel->sustain_pos[2]; player_channel->sustain_pos[3] = player_host_channel->sustain_pos[3]; player_channel->nna_pos[0] = player_host_channel->nna_pos[0]; player_channel->nna_pos[1] = player_host_channel->nna_pos[1]; player_channel->nna_pos[2] = player_host_channel->nna_pos[2]; player_channel->nna_pos[3] = player_host_channel->nna_pos[3]; player_channel->dna_pos[0] = player_host_channel->dna_pos[0]; player_channel->dna_pos[1] = player_host_channel->dna_pos[1]; player_channel->dna_pos[2] = player_host_channel->dna_pos[2]; player_channel->dna_pos[3] = player_host_channel->dna_pos[3]; player_channel->variable[0] = player_host_channel->variable[0]; player_channel->variable[1] = player_host_channel->variable[1]; player_channel->variable[2] = player_host_channel->variable[2]; player_channel->variable[3] = player_host_channel->variable[3]; player_channel->variable[4] = player_host_channel->variable[4]; player_channel->variable[5] = player_host_channel->variable[5]; player_channel->variable[6] = player_host_channel->variable[6]; player_channel->variable[7] = player_host_channel->variable[7]; player_channel->variable[8] = player_host_channel->variable[8]; player_channel->variable[9] = player_host_channel->variable[9]; player_channel->variable[10] = player_host_channel->variable[10]; player_channel->variable[11] = player_host_channel->variable[11]; player_channel->variable[12] = player_host_channel->variable[12]; player_channel->variable[13] = player_host_channel->variable[13]; player_channel->variable[14] = player_host_channel->variable[14]; player_channel->variable[15] = player_host_channel->variable[15]; player_channel->cond_var[0] = player_host_channel->cond_var[0] = synth->cond_var[0]; player_channel->cond_var[1] = player_host_channel->cond_var[1] = synth->cond_var[1]; player_channel->cond_var[2] = player_host_channel->cond_var[2] = synth->cond_var[2]; player_channel->cond_var[3] = player_host_channel->cond_var[3] = synth->cond_var[3]; player_channel->finetune = 0; player_channel->stop_forbid_mask = 0; player_channel->vibrato_pos = 0; player_channel->tremolo_pos = 0; player_channel->pannolo_pos = 0; player_channel->arpeggio_pos = 0; player_channel->synth_flags = 0; player_channel->kill_count[0] = 0; player_channel->kill_count[1] = 0; player_channel->kill_count[2] = 0; player_channel->kill_count[3] = 0; player_channel->wait_count[0] = 0; player_channel->wait_count[1] = 0; player_channel->wait_count[2] = 0; player_channel->wait_count[3] = 0; player_channel->wait_line[0] = 0; player_channel->wait_line[1] = 0; player_channel->wait_line[2] = 0; player_channel->wait_line[3] = 0; player_channel->wait_type[0] = 0; player_channel->wait_type[1] = 0; player_channel->wait_type[2] = 0; player_channel->wait_type[3] = 0; player_channel->porta_up = 0; player_channel->porta_dn = 0; player_channel->portamento = 0; player_channel->vibrato_slide = 0; player_channel->vibrato_rate = 0; player_channel->vibrato_depth = 0; player_channel->arpeggio_slide = 0; player_channel->arpeggio_speed = 0; player_channel->arpeggio_transpose = 0; player_channel->arpeggio_finetune = 0; player_channel->vol_sl_up = 0; player_channel->vol_sl_dn = 0; player_channel->tremolo_slide = 0; player_channel->tremolo_depth = 0; player_channel->tremolo_rate = 0; player_channel->pan_sl_left = 0; player_channel->pan_sl_right = 0; player_channel->pannolo_slide = 0; player_channel->pannolo_depth = 0; player_channel->pannolo_rate = 0; } player_channel->finetune = player_host_channel->finetune; mixer = avctx->player_mixer_data; if (mixer->mixctx->set_channel) mixer->mixctx->set_channel(mixer, &player_channel->mixer, player_host_channel->virtual_channel); } static uint32_t get_note(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *player_channel, const uint16_t channel) { const AVSequencerModule *const module = avctx->player_module; const AVSequencerTrack *track; const AVSequencerTrackRow *track_data; const AVSequencerInstrument *instrument; AVSequencerPlayerChannel *new_player_channel; uint32_t instr; uint16_t octave_note; uint8_t octave; int8_t note; if (player_host_channel->pattern_delay_count || (player_host_channel->tempo_counter != player_host_channel->note_delay) || (!(track = player_host_channel->track))) return 0; track_data = track->data + player_host_channel->row; if (!(track_data->octave || track_data->note || track_data->instrument)) return 0; octave_note = (track_data->octave << 8) | track_data->note; octave = track_data->octave; if ((note = track_data->note) < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_END : if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_LOOP)) { player_host_channel->flags |= AVSEQ_PLAYER_HOST_CHANNEL_FLAG_PATTERN_BREAK; player_host_channel->break_row = 0; } return 1; case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } return 0; } else if ((instr = track_data->instrument)) { instr--; if ((instr >= module->instruments) || (!(instrument = module->instrument_list[instr]))) return 0; if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { AVSequencerInstrument *instrument_scan; instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TONE_PORTA) { player_host_channel->tone_porta_target_pitch = get_tone_pitch(avctx, player_host_channel, player_channel, get_key_table_note(avctx, instrument, player_host_channel, octave, note)); return 0; } if (octave_note) { const AVSequencerSample *sample; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) player_channel = new_player_channel; sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } else { const AVSequencerSample *sample; uint16_t note; if (!instrument) return 0; if ((note = player_host_channel->instr_note)) { if ((note = get_key_table(avctx, instrument, player_host_channel, note)) == 0x8000) return 0; if ((player_channel->host_channel != channel) || (player_host_channel->instrument != instrument)) { if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; } } else { note = get_key_table(avctx, instrument, player_host_channel, 1); player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if ((new_player_channel = play_note_got(avctx, player_host_channel, player_channel, note, channel))) player_channel = new_player_channel; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED; } sample = player_host_channel->sample; player_channel->volume = sample->volume; player_channel->sub_volume = sample->sub_volume; init_new_instrument(avctx, player_host_channel, player_channel); if (!(instrument->compat_flags & AVSEQ_INSTRUMENT_COMPAT_FLAG_LOCK_INSTR_WAVE)) init_new_sample(avctx, player_host_channel, player_channel); } } else if ((instrument = player_host_channel->instrument) && module->instruments) { if (!(instrument->flags & AVSEQ_INSTRUMENT_FLAG_NO_INSTR_TRANSPOSE)) { AVSequencerOrderData *order_data = player_host_channel->order; if (order_data->instr_transpose) { const AVSequencerInstrument *instrument_scan; do { if (module->instrument_list[instr] == instrument) break; } while (++instr < module->instruments); instr += order_data->instr_transpose; if ((instr < module->instruments) && ((instrument_scan = module->instrument_list[instr]))) instrument = instrument_scan; } } if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, octave, note, channel))) { const AVSequencerSample *const sample = player_host_channel->sample; new_player_channel->mixer.pos = sample->start_offset; if (sample->compat_flags & AVSEQ_SAMPLE_COMPAT_FLAG_VOLUME_ONLY) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; } else if (player_channel != new_player_channel) { new_player_channel->volume = player_channel->volume; new_player_channel->sub_volume = player_channel->sub_volume; new_player_channel->instr_volume = player_channel->instr_volume; new_player_channel->panning = player_channel->panning; new_player_channel->sub_panning = player_channel->sub_panning; new_player_channel->final_volume = player_channel->final_volume; new_player_channel->final_panning = player_channel->final_panning; new_player_channel->global_volume = player_channel->global_volume; new_player_channel->global_sub_volume = player_channel->global_sub_volume; new_player_channel->global_panning = player_channel->global_panning; new_player_channel->global_sub_panning = player_channel->global_sub_panning; new_player_channel->volume_swing = player_channel->volume_swing; new_player_channel->panning_swing = player_channel->panning_swing; new_player_channel->pitch_swing = player_channel->pitch_swing; new_player_channel->host_channel = player_channel->host_channel; new_player_channel->flags = player_channel->flags; new_player_channel->vol_env = player_channel->vol_env; new_player_channel->pan_env = player_channel->pan_env; new_player_channel->slide_env = player_channel->slide_env; new_player_channel->resonance_env = player_channel->resonance_env; new_player_channel->auto_vib_env = player_channel->auto_vib_env; new_player_channel->auto_trem_env = player_channel->auto_trem_env; new_player_channel->auto_pan_env = player_channel->auto_pan_env; new_player_channel->slide_env_freq = player_channel->slide_env_freq; new_player_channel->auto_vibrato_freq = player_channel->auto_vibrato_freq; new_player_channel->auto_tremolo_vol = player_channel->auto_tremolo_vol; new_player_channel->auto_pannolo_pan = player_channel->auto_pannolo_pan; new_player_channel->auto_vibrato_count = player_channel->auto_vibrato_count; new_player_channel->auto_tremolo_count = player_channel->auto_tremolo_count; new_player_channel->auto_pannolo_count = player_channel->auto_pannolo_count; new_player_channel->fade_out = player_channel->fade_out; new_player_channel->fade_out_count = player_channel->fade_out_count; new_player_channel->pitch_pan_separation = player_channel->pitch_pan_separation; new_player_channel->pitch_pan_center = player_channel->pitch_pan_center; new_player_channel->dca = player_channel->dca; new_player_channel->hold = player_channel->hold; new_player_channel->decay = player_channel->decay; new_player_channel->auto_vibrato_sweep = player_channel->auto_vibrato_sweep; new_player_channel->auto_tremolo_sweep = player_channel->auto_tremolo_sweep; new_player_channel->auto_pan_sweep = player_channel->auto_pan_sweep; new_player_channel->auto_vibrato_depth = player_channel->auto_vibrato_depth; new_player_channel->auto_vibrato_rate = player_channel->auto_vibrato_rate; new_player_channel->auto_tremolo_depth = player_channel->auto_tremolo_depth; new_player_channel->auto_tremolo_rate = player_channel->auto_tremolo_rate; new_player_channel->auto_pan_depth = player_channel->auto_pan_depth; new_player_channel->auto_pan_rate = player_channel->auto_pan_rate; } init_new_instrument(avctx, player_host_channel, new_player_channel); init_new_sample(avctx, player_host_channel, new_player_channel); } } return 0; } static const void *se_lut[128] = { se_stop, se_kill, se_wait, se_waitvol, se_waitpan, se_waitsld, se_waitspc, se_jump, se_jumpeq, se_jumpne, se_jumppl, se_jumpmi, se_jumplt, se_jumple, se_jumpgt, se_jumpge, se_jumpvs, se_jumpvc, se_jumpcs, se_jumpcc, se_jumpls, se_jumphi, se_jumpvol, se_jumppan, se_jumpsld, se_jumpspc, se_call, se_ret, se_posvar, se_load, se_add, se_addx, se_sub, se_subx, se_cmp, se_mulu, se_muls, se_dmulu, se_dmuls, se_divu, se_divs, se_modu, se_mods, se_ddivu, se_ddivs, se_ashl, se_ashr, se_lshl, se_lshr, se_rol, se_ror, se_rolx, se_rorx, se_or, se_and, se_xor, se_not, se_neg, se_negx, se_extb, se_ext, se_xchg, se_swap, se_getwave, se_getwlen, se_getwpos, se_getchan, se_getnote, se_getrans, se_getptch, se_getper, se_getfx, se_getarpw, se_getarpv, se_getarpl, se_getarpp, se_getvibw, se_getvibv, se_getvibl, se_getvibp, se_gettrmw, se_gettrmv, se_gettrml, se_gettrmp, se_getpanw, se_getpanv, se_getpanl, se_getpanp, se_getrnd, se_getsine, se_portaup, se_portadn, se_vibspd, se_vibdpth, se_vibwave, se_vibwavp, se_vibrato, se_vibval, se_arpspd, se_arpwave, se_arpwavp, se_arpegio, se_arpval, se_setwave, se_isetwav, se_setwavp, se_setrans, se_setnote, se_setptch, se_setper, se_reset, se_volslup, se_volsldn, se_trmspd, se_trmdpth, se_trmwave, se_trmwavp, se_tremolo, se_trmval, se_panleft, se_panrght, se_panspd, se_pandpth, se_panwave, se_panwavp, se_pannolo, se_panval, se_nop }; static int execute_synth(AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, const int synth_type) { uint16_t synth_count = 0, bit_mask = 1 << synth_type; do { const AVSequencerSynth *synth = player_channel->synth; const AVSequencerSynthCode *synth_code = synth->code; uint16_t synth_code_line = player_channel->entry_pos[synth_type], instruction_data, i; int8_t instruction; int src_var, dst_var; synth_code += synth_code_line; if (player_channel->wait_count[synth_type]--) { exec_synth_done: if ((player_channel->synth_flags & bit_mask) && (!(player_channel->kill_count[synth_type]--))) return 0; return 1; } player_channel->wait_count[synth_type] = 0; if ((synth_code_line >= synth->size) || ((int8_t) player_channel->wait_type[synth_type] < 0)) goto exec_synth_done; i = 4 - 1; do { int8_t wait_volume_type; if (((wait_volume_type = ~player_channel->wait_type[synth_type]) >= 0) && (wait_volume_type == i) && (player_channel->wait_line[synth_type] == synth_code_line)) player_channel->wait_type[synth_type] = 0; } while (i--); instruction = synth_code->instruction; dst_var = synth_code->src_dst_var; instruction_data = synth_code->data; if (!instruction && !dst_var && !instruction_data) goto exec_synth_done; src_var = dst_var >> 4; dst_var &= 0x0F; synth_code_line++; if (instruction < 0) { const AVSequencerPlayerEffects *effects_lut; void (*check_func)(const AVSequencerContext *const avctx, AVSequencerPlayerHostChannel *const player_host_channel, AVSequencerPlayerChannel *const player_channel, const uint16_t channel, uint16_t *const fx_byte, uint16_t *const data_word, uint16_t *const flags); uint16_t fx_byte, data_word, flags; fx_byte = ~instruction; effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; data_word = instruction_data + player_channel->variable[src_var]; flags = effects_lut->flags; if ((check_func = effects_lut->check_fx_func)) { check_func(avctx, player_host_channel, player_channel, player_channel->host_channel, &fx_byte, &data_word, &flags); effects_lut = (const AVSequencerPlayerEffects *) (avctx->effects_lut ? avctx->effects_lut : fx_lut) + fx_byte; } if (!effects_lut->pre_pattern_func) { instruction_data = player_host_channel->virtual_channel; player_host_channel->virtual_channel = channel; effects_lut->effect_func(avctx, player_host_channel, player_channel, player_channel->host_channel, fx_byte, data_word); player_host_channel->virtual_channel = instruction_data; } player_channel->entry_pos[synth_type] = synth_code_line; } else { uint16_t (**fx_exec_func)(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const uint16_t virtual_channel, uint16_t synth_code_line, const int src_var, int dst_var, uint16_t instruction_data, const int synth_type); fx_exec_func = (avctx->synth_code_exec_lut ? avctx->synth_code_exec_lut : se_lut); player_channel->entry_pos[synth_type] = fx_exec_func[(uint8_t) instruction](avctx, player_channel, channel, synth_code_line, src_var, dst_var, instruction_data, synth_type); } } while (++synth_count); return 0; } static const int8_t empty_waveform[256]; int avseq_playback_handler(AVMixerData *mixer_data) { AVSequencerContext *const avctx = (AVSequencerContext *) mixer_data->opaque; const AVSequencerModule *const module = avctx->player_module; const AVSequencerSong *const song = avctx->player_song; AVSequencerPlayerGlobals *const player_globals = avctx->player_globals; AVSequencerPlayerHostChannel *player_host_channel = avctx->player_host_channel; AVSequencerPlayerChannel *player_channel = avctx->player_channel; const AVSequencerPlayerHook *player_hook; uint16_t channel, virtual_channel; if (!(module && song && player_globals && player_host_channel && player_channel)) return 0; channel = 0; do { if (mixer_data->mixctx->get_channel) mixer_data->mixctx->get_channel(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_TRACE_MODE) { if (!player_globals->trace_count--) player_globals->trace_count = 0; return 0; } player_hook = avctx->player_hook; if (player_hook && (player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END)) || (!(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END)))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->play_type & AVSEQ_PLAYER_GLOBALS_PLAY_TYPE_SONG) { uint32_t play_time_calc, play_time_advance, play_time_fraction; play_time_calc = ((uint64_t) player_globals->tempo * player_globals->relative_speed) >> 16; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_time_frac += play_time_fraction; if (player_globals->play_time_frac < play_time_fraction) play_time_advance++; player_globals->play_time += play_time_advance; play_time_calc = player_globals->tempo; play_time_advance = UINT64_C(AV_TIME_BASE * 655360) / play_time_calc; play_time_fraction = ((UINT64_C(AV_TIME_BASE * 655360) % play_time_calc) << 32) / play_time_calc; player_globals->play_tics_frac += play_time_fraction; if (player_globals->play_tics_frac < play_time_fraction) play_time_advance++; player_globals->play_tics += play_time_advance; } channel = 0; do { player_channel = avctx->player_channel + player_host_channel->virtual_channel; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE)) { const AVSequencerTrack *const old_track = player_host_channel->track; const AVSequencerTrackEffect const *old_effect = player_host_channel->effect; const uint32_t old_tempo_counter = player_host_channel->tempo_counter; const uint16_t old_row = player_host_channel->row; player_host_channel->flags &= ~(AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT|AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE); player_host_channel->track = (const AVSequencerTrack *) player_host_channel->instrument; player_host_channel->effect = NULL; player_host_channel->row = (uint32_t) player_host_channel->sample; player_host_channel->instrument = NULL; player_host_channel->sample = NULL; get_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->tempo_counter = player_host_channel->note_delay; get_note(avctx, player_host_channel, player_channel, channel); run_effects(avctx, player_host_channel, player_channel, channel); player_host_channel->track = old_track; player_host_channel->effect = old_effect; player_host_channel->tempo_counter = old_tempo_counter; player_host_channel->row = old_row; } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT) { const uint16_t note = player_host_channel->instr_note; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_INSTRUMENT; if ((int8_t) note < 0) { switch ((int) note) { case AVSEQ_TRACK_DATA_NOTE_FADE : player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; break; case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY : break; case AVSEQ_TRACK_DATA_NOTE_KEYOFF : play_key_off(player_channel); break; case AVSEQ_TRACK_DATA_NOTE_OFF : player_channel->volume = 0; break; case AVSEQ_TRACK_DATA_NOTE_KILL : player_host_channel->instrument = NULL; player_host_channel->sample = NULL; player_host_channel->instr_note = 0; player_host_channel->sample_note = 0; if (player_channel->host_channel == channel) player_channel->mixer.flags = 0; break; } } else { const AVSequencerInstrument *const instrument = player_host_channel->instrument; AVSequencerPlayerChannel *new_player_channel; if ((new_player_channel = play_note(avctx, instrument, player_host_channel, player_channel, note / 12, note % 12, channel))) player_channel = new_player_channel; player_channel->volume = player_host_channel->sample_note; player_channel->sub_volume = 0; init_new_instrument(avctx, player_host_channel, player_channel); init_new_sample(avctx, player_host_channel, player_channel); } } if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE) { const AVSequencerInstrument *instrument; const AVSequencerSample *sample = player_host_channel->sample; const uint32_t frequency = (uint32_t) player_host_channel->instrument; uint32_t i; uint16_t virtual_channel; player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SET_SAMPLE; player_host_channel->dct = 0; player_host_channel->nna = AVSEQ_PLAYER_HOST_CHANNEL_NNA_NOTE_CUT; player_host_channel->finetune = sample->finetune; player_host_channel->prev_auto_vib_env = player_channel->auto_vib_env.envelope; player_host_channel->prev_auto_trem_env = player_channel->auto_trem_env.envelope; player_host_channel->prev_auto_pan_env = player_channel->auto_pan_env.envelope; player_channel = trigger_nna(avctx, player_host_channel, player_channel, channel, (uint16_t *) &virtual_channel); sample = player_host_channel->sample; player_channel->mixer.pos = sample->start_offset; player_host_channel->virtual_channel = virtual_channel; player_channel->host_channel = channel; player_host_channel->instrument = NULL; player_channel->sample = sample; player_channel->frequency = frequency; player_channel->volume = player_host_channel->instr_note; player_channel->sub_volume = 0; player_host_channel->instr_note = 0; init_new_instrument(avctx, player_host_channel, player_channel); i = -1; while (++i < module->instruments) { uint16_t smp = -1; if (!(instrument = module->instrument_list[i])) continue; while (++smp < instrument->samples) { if (!(sample = instrument->sample_list[smp])) continue; if (sample == player_channel->sample) { player_host_channel->instrument = instrument; goto instrument_found; } } } instrument_found: player_channel->instrument = player_host_channel->instrument; init_new_sample(avctx, player_host_channel, player_channel); } - if ((!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN)) && player_host_channel->tempo) { + if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { do { process_row(avctx, player_host_channel, player_channel, channel); get_effects(avctx, player_host_channel, player_channel, channel); if (player_channel->host_channel == channel) { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_VIBRATO)) { const int32_t slide_value = player_host_channel->vibrato_slide; player_host_channel->vibrato_slide = 0; player_channel->frequency -= slide_value; } if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOLO)) { int16_t slide_value = player_host_channel->tremolo_slide; player_host_channel->tremolo_slide = 0; if ((int16_t) (slide_value = (player_channel->volume - slide_value)) < 0) slide_value = 0; if (slide_value > 255) slide_value = 255; player_channel->volume = slide_value; } } } while (get_note(avctx, player_host_channel, player_channel, channel)); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); channel = 0; player_host_channel = avctx->player_host_channel; do { - if ((!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN)) && player_host_channel->tempo) { + if (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_NO_PROC_PATTERN) && player_host_channel->tempo) { player_channel = avctx->player_channel + player_host_channel->virtual_channel; run_effects(avctx, player_host_channel, player_channel, channel); } player_host_channel->virtual_channels = 0; player_host_channel++; } while (++channel < song->channels); virtual_channel = 0; channel = 0; player_channel = avctx->player_channel; do { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_ALLOCATED) player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { const AVSequencerSample *sample; AVSequencerPlayerEnvelope *player_envelope; uint32_t frequency, host_volume, virtual_volume; uint32_t auto_vibrato_depth, auto_vibrato_count; int32_t auto_vibrato_value; uint16_t flags, slide_envelope_value; int16_t panning, abs_panning, panning_envelope_value; player_host_channel = avctx->player_host_channel + player_channel->host_channel; player_envelope = &player_channel->vol_env; if (player_envelope->tempo) { const uint16_t volume = run_envelope(avctx, player_envelope, 1, -0x8000); if (!player_envelope->tempo) { if (!(volume >> 8)) goto turn_note_off; player_channel->flags |= AVSEQ_PLAYER_CHANNEL_FLAG_FADING; } } run_envelope(avctx, &player_channel->pan_env, 1, 0); slide_envelope_value = run_envelope(avctx, &player_channel->slide_env, 1, 0); if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_PORTA_SLIDE_ENV) { const uint32_t old_frequency = player_channel->frequency; player_channel->frequency += player_channel->slide_env_freq; if ((frequency = player_channel->frequency)) { if ((int16_t) slide_envelope_value < 0) { slide_envelope_value = -slide_envelope_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) frequency = linear_slide_down(avctx, player_channel, frequency, slide_envelope_value); else frequency = amiga_slide_down(player_channel, frequency, slide_envelope_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_SLIDE_ENV) { frequency = linear_slide_up(avctx, player_channel, frequency, slide_envelope_value); } else { frequency = amiga_slide_up(player_channel, frequency, slide_envelope_value); } player_channel->slide_env_freq += old_frequency - frequency; } } else { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_envelope_frequency, old_frequency; int16_t octave, note; const int16_t slide_note = (int16_t) slide_envelope_value >> 8; int16_t finetune = slide_envelope_value & 0xFF; octave = slide_note / 12; note = slide_note % 12; if (note < 0) { octave--; note += 12; finetune = -finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (int32_t) (finetune * (int16_t) next_frequency) >> 8; if ((int16_t) octave < 0) { octave = -octave; frequency >>= octave; } else { frequency <<= octave; } slide_envelope_frequency = player_channel->slide_env_freq; old_frequency = player_channel->frequency; slide_envelope_frequency += old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_envelope_frequency) >> 16; player_channel->slide_env_freq += old_frequency - frequency; } if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_FADING) { int32_t fade_out = (uint32_t) player_channel->fade_out_count; if ((fade_out -= (int32_t) player_channel->fade_out) <= 0) goto turn_note_off; player_channel->fade_out_count = fade_out; } auto_vibrato_value = run_envelope(avctx, &player_channel->auto_vib_env, player_channel->auto_vibrato_rate, 0); auto_vibrato_depth = player_channel->auto_vibrato_depth << 8; auto_vibrato_count = (uint32_t) player_channel->auto_vibrato_count + player_channel->auto_vibrato_sweep; if (auto_vibrato_count > auto_vibrato_depth) auto_vibrato_count = auto_vibrato_depth; player_channel->auto_vibrato_count = auto_vibrato_count; auto_vibrato_count >>= 8; if ((auto_vibrato_value *= (int32_t) -auto_vibrato_count)) { uint32_t old_frequency = player_channel->frequency; auto_vibrato_value >>= 7 - 2; player_channel->frequency -= player_channel->auto_vibrato_freq; if ((frequency = player_channel->frequency)) { if (auto_vibrato_value < 0) { auto_vibrato_value = -auto_vibrato_value; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) frequency = linear_slide_up(avctx, player_channel, frequency, auto_vibrato_value); else frequency = amiga_slide_up(player_channel, frequency, auto_vibrato_value); } else if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_LINEAR_FREQ_AUTO_VIB) { frequency = linear_slide_down(avctx, player_channel, frequency, auto_vibrato_value); } else { frequency = amiga_slide_down(player_channel, frequency, auto_vibrato_value); } player_channel->auto_vibrato_freq -= old_frequency - frequency; } } if ((sample = player_channel->sample) && sample->synth) { if (!(execute_synth(avctx, player_host_channel, player_channel, channel, 0))) goto turn_note_off; if (!(execute_synth(avctx, player_host_channel, player_channel, channel, 1))) goto turn_note_off; if (!(execute_synth(avctx, player_host_channel, player_channel, channel, 2))) goto turn_note_off; if (!(execute_synth(avctx, player_host_channel, player_channel, channel, 3))) goto turn_note_off; } - if (((!(player_channel->mixer.data)) || (!(player_channel->mixer.bits_per_sample))) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { + if ((!player_channel->mixer.data || !player_channel->mixer.bits_per_sample) && (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY)) { player_channel->mixer.pos = 0; player_channel->mixer.len = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.data = (int16_t *) &empty_waveform; player_channel->mixer.repeat_start = 0; player_channel->mixer.repeat_length = (sizeof (empty_waveform) / sizeof (empty_waveform[0])); player_channel->mixer.repeat_count = 0; player_channel->mixer.repeat_counted = 0; player_channel->mixer.bits_per_sample = (sizeof (empty_waveform[0]) * 8); player_channel->mixer.flags = AVSEQ_MIXER_CHANNEL_FLAG_LOOP|AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } frequency = player_channel->frequency; if (sample) { if (frequency < sample->rate_min) frequency = sample->rate_min; if (frequency > sample->rate_max) frequency = sample->rate_max; } if (!(player_channel->frequency = frequency)) { turn_note_off: player_channel->mixer.flags = 0; goto not_calculate_no_playing; } if (!(player_channel->mixer.rate = ((uint64_t) frequency * player_globals->relative_pitch) >> 16)) goto turn_note_off; if (!(song->compat_flags & AVSEQ_SONG_COMPAT_FLAG_GLOBAL_NEW_ONLY)) { player_channel->global_volume = player_globals->global_volume; player_channel->global_sub_volume = player_globals->global_sub_volume; player_channel->global_panning = player_globals->global_panning; player_channel->global_sub_panning = player_globals->global_sub_panning; } host_volume = player_channel->volume; player_host_channel->virtual_channels++; virtual_channel++; - if ((!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND)) && (player_host_channel->virtual_channel == channel) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF)) + if (!(player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_BACKGROUND) && (player_host_channel->virtual_channel == channel) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_EXEC) && (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TREMOR_OFF)) host_volume = 0; host_volume *= (uint16_t) player_host_channel->track_volume * (uint16_t) player_channel->instr_volume; virtual_volume = (((uint16_t) player_channel->vol_env.value >> 8) * (uint16_t) player_channel->global_volume) * (uint16_t) player_channel->fade_out_count; player_channel->mixer.volume = player_channel->final_volume = ((uint64_t) host_volume * virtual_volume) / UINT64_C(70660093200890625); /* / (255ULL*255ULL*255ULL*255ULL*65535ULL*255ULL) */ flags = 0; player_channel->flags &= ~AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND; player_channel->mixer.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SMP_SUR_PAN) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning = (uint8_t) player_channel->panning; if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_TRACK_PAN) { panning = (uint8_t) player_host_channel->track_panning; flags = 0; if ((player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_TRACK_SUR_PAN) || (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_CHANNEL_SUR_PAN)) flags = AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; } player_channel->flags |= flags; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) player_channel->mixer.flags |= flags; if (panning == 255) panning++; panning_envelope_value = panning; if ((int16_t) (panning = (128 - panning)) < 0) panning = -panning; abs_panning = 128 - panning; panning = player_channel->pan_env.value >> 8; if (panning == 127) panning++; panning = 128 - (((panning * abs_panning) >> 7) + panning_envelope_value); abs_panning = (uint8_t) player_host_channel->channel_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning_envelope_value = abs_panning = ((panning * abs_panning) >> 7) + 128; if (panning_envelope_value > 255) panning_envelope_value = 255; player_channel->final_panning = panning_envelope_value; panning = 128; if (!(song->flags & AVSEQ_SONG_FLAG_MONO)) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_GLOBAL_SUR_PAN) player_channel->mixer.flags |= AVSEQ_MIXER_CHANNEL_FLAG_SURROUND; panning -= abs_panning; abs_panning = (uint8_t) player_channel->global_panning; if (abs_panning == 255) abs_panning++; abs_panning -= 128; panning = ((panning * abs_panning) >> 7) + 128; if (panning == 256) panning--; } player_channel->mixer.panning = panning; if (mixer_data->mixctx->set_channel_volume_panning_pitch) mixer_data->mixctx->set_channel_volume_panning_pitch(mixer_data, &player_channel->mixer, channel); } not_calculate_no_playing: if (mixer_data->mixctx->set_channel_position_repeat_flags) mixer_data->mixctx->set_channel_position_repeat_flags(mixer_data, &player_channel->mixer, channel); player_channel++; } while (++channel < module->channels); player_globals->channels = virtual_channel; if (virtual_channel > player_globals->max_channels) player_globals->max_channels = virtual_channel; channel = 0; player_host_channel = avctx->player_host_channel; do { if (!(player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END)) goto check_song_end_done; player_host_channel++; } while (++channel < song->channels); player_globals->flags |= AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END; check_song_end_done: if (player_hook && (!(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_BEGINNING)) && (((player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END) && (!(player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END))) || (!(player_hook->flags & AVSEQ_PLAYER_HOOK_FLAG_SONG_END)))) player_hook->hook_func(avctx, player_hook->hook_data, player_hook->hook_len); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SONG_END) { player_host_channel = avctx->player_host_channel; if (player_host_channel->flags & AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END) { AVSequencerOrderList *order_list = song->order_list; channel = song->channels; do { AVSequencerOrderData *order_data; uint32_t i = -1; if (player_host_channel->tempo) player_host_channel->flags &= ~AVSEQ_PLAYER_HOST_CHANNEL_FLAG_SONG_END; while (++i < order_list->orders) { if ((order_data = order_list->order_data[i]) && (order_data != player_host_channel->order)) order_data->played = 0; } order_list++; player_host_channel++; } while (--channel); } } return 0; }
BastyCDGS/ffmpeg-soc
f15998ebe6032db27e72bee0bdfd3ee35f7c5ab3
Fixed libavformat/iff.c to transfer the first channel to the original mixer after finished seeking.
diff --git a/libavformat/iff.c b/libavformat/iff.c index 06997b0..f723581 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -2482,563 +2482,563 @@ static int open_tcm1_keyb(AVFormatContext *s, AVSequencerModule *module, uint32_ keyboard->key[i].sample = get_be16(pb); keyboard->key[i].octave = get_byte(pb); keyboard->key[i].note = get_byte(pb); } break; default: // TODO: Add unknown chunk break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } return 0; } static int open_tcm1_arpl(AVFormatContext *s, AVSequencerModule *module, uint32_t data_size) { ByteIOContext *pb = s->pb; uint32_t iff_size = 4; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_FORM: switch (get_le32(pb)) { case ID_ARPG: if ((res = open_arpl_arpg(s, module, iff_size)) < 0) return res; break; } break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } return 0; } static int open_arpl_arpg(AVFormatContext *s, AVSequencerModule *module, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerArpeggio *arpeggio; uint32_t iff_size = 4; uint16_t entries = 0; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; if (!(arpeggio = avseq_arpeggio_create())) return AVERROR(ENOMEM); if ((res = avseq_arpeggio_open(module, arpeggio, 1)) < 0) { avseq_arpeggio_destroy(arpeggio); return res; } while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; const char *metadata_tag = NULL; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_AHDR: entries = get_be16(pb); arpeggio->flags = get_be16(pb); arpeggio->sustain_start = get_be16(pb); arpeggio->sustain_end = get_be16(pb); arpeggio->sustain_count = get_be16(pb); arpeggio->loop_start = get_be16(pb); arpeggio->loop_end = get_be16(pb); arpeggio->loop_count = get_be16(pb); break; case ID_FORM: switch (get_le32(pb)) { case ID_ARPE: if ((res = open_arpg_arpe(s, arpeggio, iff_size)) < 0) return res; break; default: // TODO: Add unknown chunk break; } break; case ID_ANNO: case ID_TEXT: metadata_tag = "comment"; break; case ID_AUTH: metadata_tag = "artist"; break; case ID_COPYRIGHT: metadata_tag = "copyright"; break; case ID_FILE: metadata_tag = "file"; break; case ID_NAME: metadata_tag = "title"; break; default: // TODO: Add unknown chunk break; } if (metadata_tag) { if ((res = seq_get_metadata(s, &arpeggio->metadata, metadata_tag, iff_size)) < 0) { av_log(arpeggio, AV_LOG_ERROR, "Cannot allocate metadata tag %s!\n", metadata_tag); return res; } } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if (entries != arpeggio->entries) { av_log(arpeggio, AV_LOG_ERROR, "Number of attached arpeggio entries does not match actual reads (expected: %d, got: %d)!\n", arpeggio->entries, entries); return AVERROR_INVALIDDATA; } return 0; } static int open_arpg_arpe(AVFormatContext *s, AVSequencerArpeggio *arpeggio, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerArpeggioData *data; uint32_t iff_size = 4; uint16_t ticks = 0; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_ARPE: if (ticks) { if ((res = avseq_arpeggio_data_open(arpeggio, arpeggio->entries + 1)) < 0) { return res; } } ticks = arpeggio->entries; data = &(arpeggio->data[ticks - 1]); data->tone = get_byte(pb); data->transpose = get_byte(pb); data->instrument = get_be16(pb); data->command[0] = get_byte(pb); data->command[1] = get_byte(pb); data->command[2] = get_byte(pb); data->command[3] = get_byte(pb); data->data[0] = get_be16(pb); data->data[1] = get_be16(pb); data->data[2] = get_be16(pb); data->data[3] = get_be16(pb); break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if (!ticks) { av_log(arpeggio, AV_LOG_ERROR, "Attached arpeggio structure entries do not match actual reads!\n"); return AVERROR_INVALIDDATA; } return 0; } #endif static const char *nna_name[] = {"Cut", "Con", "Off", "Fde"}; static const char *note_name[] = {"--", "C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}; static const char *spec_note_name[] = {"END", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "-\\-", "-|-", "===", "^^-", "^^^"}; static int iff_read_packet(AVFormatContext *s, AVPacket *pkt) { IffDemuxContext *iff = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st = s->streams[0]; int ret; if(iff->sent_bytes >= iff->body_size) return AVERROR_EOF; #if CONFIG_AVSEQUENCER if (iff->avctx) { int32_t row; uint16_t channel; const AVSequencerPlayerGlobals *const player_globals = iff->avctx->player_globals; const AVSequencerPlayerHostChannel *player_host_channel = iff->avctx->player_host_channel; const AVSequencerPlayerChannel *player_channel; char *buf; AVMixerData *mixer_data = iff->avctx->player_mixer_data; const int size = st->codec->channels * mixer_data->mix_buf_size << 2; avseq_mixer_do_mix(mixer_data, NULL); if (!(buf = av_malloc(16 * iff->avctx->player_song->channels))) { avsequencer_destroy(iff->avctx); iff->avctx = NULL; av_log(s, AV_LOG_ERROR, "Cannot allocate pattern display buffer!\n"); return AVERROR(ENOMEM); } snprintf(buf, 16 * iff->avctx->player_song->channels, " Row "); for (channel = 0; channel < iff->avctx->player_song->channels; ++channel) { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%3d ", channel + 1); } av_log(NULL, AV_LOG_INFO, "\n\n\n%s \n", buf); for (row = FFMAX(FFMIN((int32_t) player_host_channel->row - 11, (int32_t) player_host_channel->max_row - 24), 0); row <= FFMIN(FFMAX((int32_t) player_host_channel->row + 12, 23), (int32_t) player_host_channel->max_row - 1); ++row) { if (row == player_host_channel->row) snprintf(buf, 16 * iff->avctx->player_song->channels, ">%04X ", row); else snprintf(buf, 16 * iff->avctx->player_song->channels, " %04X ", row); channel = 0; do { if (player_host_channel->track) { AVSequencerTrackRow *track_row = player_host_channel->track->data + row; switch (track_row->note) { case AVSEQ_TRACK_DATA_NOTE_NONE: if (track_row->effects) { AVSequencerTrackEffect *fx = track_row->effects_data[0]; if (fx->command || fx->data) snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%02X%02X", fx->command, fx->data >> 8 ? fx->data >> 8 : fx->data & 0xFF); else snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } else { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } break; case AVSEQ_TRACK_DATA_NOTE_C: case AVSEQ_TRACK_DATA_NOTE_C_SHARP: case AVSEQ_TRACK_DATA_NOTE_D: case AVSEQ_TRACK_DATA_NOTE_D_SHARP: case AVSEQ_TRACK_DATA_NOTE_E: case AVSEQ_TRACK_DATA_NOTE_F: case AVSEQ_TRACK_DATA_NOTE_F_SHARP: case AVSEQ_TRACK_DATA_NOTE_G: case AVSEQ_TRACK_DATA_NOTE_G_SHARP: case AVSEQ_TRACK_DATA_NOTE_A: case AVSEQ_TRACK_DATA_NOTE_A_SHARP: case AVSEQ_TRACK_DATA_NOTE_B: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%2s%1d ", note_name[track_row->note], track_row->octave); break; case AVSEQ_TRACK_DATA_NOTE_KILL: case AVSEQ_TRACK_DATA_NOTE_OFF: case AVSEQ_TRACK_DATA_NOTE_KEYOFF: case AVSEQ_TRACK_DATA_NOTE_HOLD_DELAY: case AVSEQ_TRACK_DATA_NOTE_FADE: case AVSEQ_TRACK_DATA_NOTE_END: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "%3s ", spec_note_name[(uint8_t) track_row->note - 0xF0]); break; default: snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "??? "); break; } } else { snprintf(buf + strlen(buf), 16 * iff->avctx->player_song->channels - strlen(buf), "... "); } player_host_channel++; } while (++channel < iff->avctx->player_song->channels); av_log(NULL, AV_LOG_INFO, "%s\n", buf); player_host_channel = iff->avctx->player_host_channel; } av_log(NULL, AV_LOG_INFO, "\nVch Frequency Position Ch Row Tick Tm FVl Vl CV SV VE Fade Pn PE NNA Tot\n"); player_channel = iff->avctx->player_channel; channel = 0; do { player_host_channel = iff->avctx->player_host_channel + player_channel->host_channel; if (player_channel->mixer.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { if (player_channel->flags & AVSEQ_PLAYER_CHANNEL_FLAG_SURROUND) av_log(NULL, AV_LOG_INFO, "%3d %9d %8d %3d %04X %04X %02X %3d %02X %02X %02X %02X %04X Su %02X %s %3d\n", channel + 1, player_channel->mixer.rate, player_channel->mixer.pos, player_channel->host_channel, player_host_channel->row, player_host_channel->tempo_counter, player_host_channel->tempo, player_channel->final_volume, player_channel->volume, player_host_channel->track_volume, player_channel->instr_volume / 255, (uint16_t) player_channel->vol_env.value / 256, player_channel->fade_out_count, (player_channel->pan_env.value >> 8) + 128, nna_name[player_host_channel->nna], player_host_channel->virtual_channels); else av_log(NULL, AV_LOG_INFO, "%3d %9d %8d %3d %04X %04X %02X %3d %02X %02X %02X %02X %04X %02X %02X %s %3d\n", channel + 1, player_channel->mixer.rate, player_channel->mixer.pos, player_channel->host_channel, player_host_channel->row, player_host_channel->tempo_counter, player_host_channel->tempo, player_channel->final_volume, player_channel->volume, player_host_channel->track_volume, player_channel->instr_volume / 255, (uint16_t) player_channel->vol_env.value / 256, player_channel->fade_out_count, (uint8_t) player_channel->final_panning, (player_channel->pan_env.value >> 8) + 128, nna_name[player_host_channel->nna], player_host_channel->virtual_channels); } else { av_log(NULL, AV_LOG_INFO, "%3d --- 0\n", channel + 1); } player_channel++; } while (++channel < FFMIN(iff->avctx->player_module->channels, 24)); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SPD_TIMING) { snprintf(buf, 16, "%d (%d)", player_globals->channels, player_globals->max_channels); if (player_globals->speed_mul < 2 && player_globals->speed_div < 2) av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d (SPD)\n", buf, player_globals->spd_speed); else av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d (%d/%d SPD)\n", buf, player_globals->spd_speed, player_globals->speed_mul, player_globals->speed_div); } else { snprintf(buf, 16, "%d (%d)", player_globals->channels, player_globals->max_channels); if (player_globals->speed_mul < 2 && player_globals->speed_div < 2) av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d/%d (BpM)\n", buf, player_globals->bpm_speed, player_globals->bpm_tempo); else av_log(NULL, AV_LOG_INFO, "Active Channels: %-13s Speed: %d/%d (%d/%d BpM)\n", buf, player_globals->bpm_speed, player_globals->bpm_tempo, player_globals->speed_mul, player_globals->speed_div); } av_free(buf); if (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_SURROUND) av_log(NULL, AV_LOG_INFO, " Global Volume: %3d Global Panning: Su\n", player_globals->global_volume); else av_log(NULL, AV_LOG_INFO, " Global Volume: %3d Global Panning: %02X\n", player_globals->global_volume, (uint8_t) player_globals->global_panning); player_host_channel = iff->avctx->player_host_channel; av_log(NULL, AV_LOG_INFO, "\033[%dA\n", FFMIN(iff->avctx->player_module->channels, 24) + 33); if ((ret = av_new_packet(pkt, size)) < 0) { avsequencer_destroy(iff->avctx); iff->avctx = NULL; av_log(s, AV_LOG_ERROR, "Cannot allocate packet!\n"); return ret; } memcpy(pkt->data, mixer_data->mix_buf, size); iff->sent_bytes += size; pkt->duration = mixer_data->mix_buf_size; st->time_base = (AVRational) {1, st->codec->sample_rate}; pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = 0; pkt->pts = iff->audio_frame_count; iff->audio_frame_count += mixer_data->mix_buf_size; return size; } #endif if(st->codec->channels == 2) { uint8_t sample_buffer[PACKET_SIZE]; ret = get_buffer(pb, sample_buffer, PACKET_SIZE); if(av_new_packet(pkt, PACKET_SIZE) < 0) { av_log(s, AV_LOG_ERROR, "iff: cannot allocate packet \n"); return AVERROR(ENOMEM); } interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ret = av_get_packet(pb, pkt, iff->body_size); } else { ret = av_get_packet(pb, pkt, PACKET_SIZE); } if(iff->sent_bytes == 0) pkt->flags |= AV_PKT_FLAG_KEY; if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { iff->sent_bytes += PACKET_SIZE; } else { iff->sent_bytes = iff->body_size; } pkt->stream_index = 0; if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { pkt->pts = iff->audio_frame_count; iff->audio_frame_count += ret / st->codec->channels; } return ret; } static int iff_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[0]; #if CONFIG_AVSEQUENCER IffDemuxContext *iff; AVMixerContext *mixctx; AVMixerData *mixer_data; #endif switch (st->codec->codec_tag) { #if CONFIG_AVSEQUENCER case ID_TCM1: iff = s->priv_data; if (!iff->avctx) return -1; if ((mixctx = avseq_mixer_get_by_name("Null mixer"))) { AVSequencerPlayerGlobals *player_globals; AVMixerData *mixer_data; AVMixerData *old_mixer_data = iff->avctx->player_mixer_data; uint32_t tempo; uint16_t channel; int res, size; if (timestamp < 0) timestamp = 0; iff->avctx->player_mixer_data = NULL; avseq_module_stop(iff->avctx, 0); if (flags & AVSEEK_FLAG_BACKWARD) { if ((res = avseq_song_reset(iff->avctx, iff->avctx->player_song)) < 0) { iff->avctx->player_mixer_data = old_mixer_data; avsequencer_destroy(iff->avctx); iff->avctx = NULL; return res; } iff->sent_bytes = 0; iff->audio_frame_count = 0; } player_globals = iff->avctx->player_globals; if ((res = avseq_module_play(iff->avctx, mixctx, iff->avctx->player_module, iff->avctx->player_song, iff->args, iff->opaque, (player_globals->flags & AVSEQ_PLAYER_GLOBALS_FLAG_PLAY_ONCE) ? 0 : 1)) < 0) { avseq_module_stop(iff->avctx, 0); iff->avctx->player_mixer_data = old_mixer_data; avsequencer_destroy(iff->avctx); iff->avctx = NULL; return res; } mixer_data = iff->avctx->player_mixer_data; tempo = avseq_song_calc_speed(iff->avctx, iff->avctx->player_song); mixer_data->flags |= AVSEQ_MIXER_DATA_FLAG_MIXING; avseq_mixer_set_rate(mixer_data, st->codec->sample_rate, st->codec->channels); avseq_mixer_set_tempo(mixer_data, tempo); avseq_mixer_set_volume(mixer_data, 0, 0, 0, iff->avctx->player_module->channels); size = st->codec->channels * mixer_data->mix_buf_size << 2; timestamp = (timestamp * AV_TIME_BASE * st->time_base.num) / st->time_base.den; if (flags & AVSEEK_FLAG_BACKWARD) { timestamp += player_globals->play_time; } else { channel = iff->avctx->player_module->channels - 1; do { AVMixerChannel mixer_channel_current; AVMixerChannel mixer_channel_next; avseq_mixer_get_both_channels(old_mixer_data, &mixer_channel_current, &mixer_channel_next, channel); avseq_mixer_set_both_channels(mixer_data, &mixer_channel_current, &mixer_channel_next, channel); - } while (--channel); + } while (channel--); } while (player_globals->play_time < timestamp) { avseq_mixer_do_mix(mixer_data, NULL); iff->sent_bytes += size; iff->audio_frame_count += mixer_data->mix_buf_size; } channel = iff->avctx->player_module->channels - 1; do { AVMixerChannel mixer_channel_current; AVMixerChannel mixer_channel_next; avseq_mixer_get_both_channels(mixer_data, &mixer_channel_current, &mixer_channel_next, channel); avseq_mixer_reset_channel(old_mixer_data, channel); avseq_mixer_set_both_channels(old_mixer_data, &mixer_channel_current, &mixer_channel_next, channel); - } while (--channel); + } while (channel--); avseq_module_stop(iff->avctx, 0); iff->avctx->player_mixer_data = old_mixer_data; } else { mixer_data = iff->avctx->player_mixer_data; mixctx = mixer_data->mixctx; } break; #endif default: break; } if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) return pcm_read_seek(s, stream_index, timestamp, flags); return -1; } AVInputFormat iff_demuxer = { "IFF", NULL_IF_CONFIG_SMALL("IFF format"), sizeof(IffDemuxContext), iff_probe, iff_read_header, iff_read_packet, NULL, iff_read_seek, .flags = AVSEEK_FLAG_ANY };
BastyCDGS/ffmpeg-soc
c0f3f1c2e7d412f6e813d2b000913da34f346f93
Some optimization in the mixers and bug fixed regarding wrong reinit of mixer after seeking.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index cd1db34..2721965 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -3763,906 +3763,915 @@ static void set_sample_mix_rate(const AV_HQMixerData *const mixer_data, struct C { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } static void update_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } static void set_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_HQMixerData *hq_mixer_data; AV_HQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned real16bit = 1, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(hq_mixer_data = av_mallocz(sizeof(AV_HQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(hq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mixer_data.mixctx = mixctx; buf_size = hq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=false;") || av_stristr(args, "real16bit=disabled;")) real16bit = 0; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->channel_info = channel_info; hq_mixer_data->mixer_data.channels_in = channels_in; hq_mixer_data->channels_in = channels_in; hq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mix_buf_size = mix_buf_mem_size; hq_mixer_data->buf = buf; hq_mixer_data->buf_size = buf_size; hq_mixer_data->mixer_data.mix_buf_size = hq_mixer_data->buf_size; hq_mixer_data->mixer_data.mix_buf = hq_mixer_data->buf; channel_rate = hq_mixer_data->mixer_data.mixctx->frequency; hq_mixer_data->mixer_data.rate = channel_rate; hq_mixer_data->mix_rate = channel_rate; hq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->filter_buf = buf; for (i = hq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) hq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_HQMixerData *hq_mixer_data = (AV_HQMixerData *) mixer_data; if (!hq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->filter_buf); av_free(hq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t channel_rate = hq_mixer_data->mix_rate * 10; uint64_t pass_value; hq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) hq_mixer_data->mix_rate_frac >> 16); hq_mixer_data->pass_len = (uint64_t) pass_value / hq_mixer_data->mixer_data.tempo; hq_mixer_data->pass_len_frac = (((uint64_t) pass_value % hq_mixer_data->mixer_data.tempo) << 32) / hq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; hq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = hq_mixer_data->mixer_data.mix_buf_size; hq_mixer_data->mixer_data.channels_out = new_channels; if ((hq_mixer_data->buf_size * hq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = hq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = hq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return hq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return hq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); hq_mixer_data->mixer_data.mix_buf = buf; hq_mixer_data->mixer_data.mix_buf_size = buf_size; hq_mixer_data->filter_buf = filter_buf; } hq_mixer_data->channels_out = new_channels; hq_mixer_data->buf = hq_mixer_data->mixer_data.mix_buf; hq_mixer_data->buf_size = hq_mixer_data->mixer_data.mix_buf_size; if (hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (hq_mixer_data->mix_rate != mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; update_sample_filter(hq_mixer_data, &channel_info->current); update_sample_filter(hq_mixer_data, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && (!(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE)))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { int32_t *volume_lut = hq_mixer_data->volume_lut; int32_t volume_mult = 0, volume_div = channels << 8; uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; + set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); - set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; + channel_block->prev_sample = 0; + channel_block->curr_sample = 0; + channel_block->next_sample = 0; + channel_block->prev_sample_r = 0; + channel_block->curr_sample_r = 0; + channel_block->next_sample_r = 0; set_sample_filter(hq_mixer_data, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; - - channel_block->prev_sample = 0; - channel_block->curr_sample = 0; - channel_block->next_sample = 0; - + channel_block->prev_sample = 0; + channel_block->curr_sample = 0; + channel_block->next_sample = 0; + channel_block->prev_sample_r = 0; + channel_block->curr_sample_r = 0; + channel_block->next_sample_r = 0; + + set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; channel_block->prev_sample = 0; channel_block->curr_sample = 0; channel_block->next_sample = 0; - channel_block->prev_sample = 0; - channel_block->curr_sample = 0; - channel_block->next_sample = 0; + channel_block->prev_sample_r = 0; + channel_block->curr_sample_r = 0; + channel_block->next_sample_r = 0; + set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); - set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; channel_block->prev_sample = 0; channel_block->curr_sample = 0; channel_block->next_sample = 0; - channel_block->prev_sample = 0; - channel_block->curr_sample = 0; - channel_block->next_sample = 0; + channel_block->prev_sample_r = 0; + channel_block->curr_sample_r = 0; + channel_block->next_sample_r = 0; + set_sample_mix_rate(hq_mixer_data, channel_block, channel_block->rate); set_sample_filter(hq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); - set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; set_sample_filter(hq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext high_quality_mixer = { .av_class = &avseq_high_quality_mixer_class, .name = "High quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for quality and supports advanced interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, }; #endif /* CONFIG_HIGH_QUALITY_MIXER */ diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 79637e1..821b23d 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -3404,890 +3404,892 @@ static void set_sample_mix_rate(const AV_LQMixerData *const mixer_data, struct C set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } static void update_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } static void set_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_LQMixerData *lq_mixer_data; AV_LQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned interpolation = 0, real16bit = 0, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(lq_mixer_data = av_mallocz(sizeof(AV_LQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(lq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mixer_data.mixctx = mixctx; buf_size = lq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=true;") || av_stristr(args, "real16bit=enabled;")) real16bit = 1; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (av_stristr(args, "interpolation=true;") || av_stristr(args, "interpolation=enabled;")) interpolation = 2; else if ((cfg_buf = av_stristr(args, "interpolation="))) sscanf(cfg_buf, "interpolation=%d;", &interpolation); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->channel_info = channel_info; lq_mixer_data->mixer_data.channels_in = channels_in; lq_mixer_data->channels_in = channels_in; lq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mix_buf_size = mix_buf_mem_size; lq_mixer_data->buf = buf; lq_mixer_data->buf_size = buf_size; lq_mixer_data->mixer_data.mix_buf_size = lq_mixer_data->buf_size; lq_mixer_data->mixer_data.mix_buf = lq_mixer_data->buf; channel_rate = lq_mixer_data->mixer_data.mixctx->frequency; lq_mixer_data->mixer_data.rate = channel_rate; lq_mixer_data->mix_rate = channel_rate; lq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; lq_mixer_data->interpolation = interpolation >= 2 ? 2 : interpolation; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->filter_buf = buf; for (i = lq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) lq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_LQMixerData *lq_mixer_data = (AV_LQMixerData *) mixer_data; if (!lq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->filter_buf); av_free(lq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t channel_rate = lq_mixer_data->mix_rate * 10; uint64_t pass_value; lq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) lq_mixer_data->mix_rate_frac >> 16); lq_mixer_data->pass_len = (uint64_t) pass_value / lq_mixer_data->mixer_data.tempo; lq_mixer_data->pass_len_frac = (((uint64_t) pass_value % lq_mixer_data->mixer_data.tempo) << 32) / lq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; lq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = lq_mixer_data->mixer_data.mix_buf_size; lq_mixer_data->mixer_data.channels_out = new_channels; if ((lq_mixer_data->buf_size * lq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = lq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = lq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return lq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return lq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); lq_mixer_data->mixer_data.mix_buf = buf; lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = new_channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; update_sample_filter(lq_mixer_data, &channel_info->current); update_sample_filter(lq_mixer_data, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = lq_mixer_data->channels_in) != channels) && (!(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE)))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { int32_t *volume_lut = lq_mixer_data->volume_lut; int32_t volume_mult = 0, volume_div = channels << 8; uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; + set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); - set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; + set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; + set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; + set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); - set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; + set_sample_mix_rate(lq_mixer_data, channel_block, channel_block->rate); set_sample_filter(lq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); - set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; set_sample_filter(lq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, }; #endif /* CONFIG_LOW_QUALITY_MIXER */
BastyCDGS/ffmpeg-soc
dbc3fab21b8cf5fba5507d3f414c684e1eb4f219
Fixed small calculation bug in volume table calculation in both low and high quality mixers.
diff --git a/libavformat/iff.c b/libavformat/iff.c index 06997b0..3e1152c 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -197,1024 +197,1025 @@ static int get_metadata(AVFormatContext *s, if (get_buffer(s->pb, buf, data_size) < 0) { av_free(buf); return AVERROR(EIO); } buf[data_size] = 0; av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); return 0; } static int iff_probe(AVProbeData *p) { const uint8_t *d = p->buf; if (AV_RL32(d) != ID_FORM) return 0; if (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) return AVPROBE_SCORE_MAX; #if CONFIG_AVSEQUENCER if (AV_RL32(d+8) == ID_TCM1) return AVPROBE_SCORE_MAX; #endif return 0; } static int iff_read_header(AVFormatContext *s, AVFormatParameters *ap) { IffDemuxContext *iff = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; #if CONFIG_AVSEQUENCER AVSequencerModule *module = NULL; uint8_t buf[24]; const char *args = "interpolation=0; real16bit=true; load_samples=true; samples_dir=; load_synth_code_symbols=true;"; void *opaque = NULL; uint32_t tracks = 0, samples = 0, synths = 0; uint16_t songs = 0, instruments = 0, envelopes = 0, keyboards = 0, arpeggios = 0; unsigned year, month, day, hour, min, sec, cts; #endif uint32_t chunk_id, data_size; int compression = -1, res; st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->channels = 1; url_fskip(pb, 8); // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content st->codec->codec_tag = get_le32(pb); #if CONFIG_AVSEQUENCER if (st->codec->codec_tag == ID_TCM1) { if (!(iff->avctx = avsequencer_open(NULL, args, opaque))) return AVERROR(ENOMEM); iff->args = args; iff->opaque = opaque; if (!(module = avseq_module_create())) { avsequencer_destroy(iff->avctx); return AVERROR(ENOMEM); } if ((res = avseq_module_open(iff->avctx, module)) < 0) { avseq_module_destroy(module); avsequencer_destroy(iff->avctx); return res; } avseq_module_set_channels(iff->avctx, module, 1); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } #endif while(!url_feof(pb)) { uint64_t orig_pos; const char *metadata_tag = NULL; chunk_id = get_le32(pb); data_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { #if CONFIG_AVSEQUENCER case ID_MHDR: if (!module) break; if ((res = get_byte(pb)) != 1) { // version avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Invalid version: %d.%d\n", res, get_byte(pb)); return AVERROR_INVALIDDATA; } compression = get_byte(pb); // revision day = get_byte(pb); month = get_byte(pb); year = get_be16(pb); hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (day || month || year || hour || min || sec || cts) { if (month == 0 || month > 12 || day == 0 || day > 31 || hour > 23 || min > 59 || sec > 59 || cts > 99) { av_log(module, AV_LOG_WARNING, "Invalid begin composing date: %04d-%02d-%02d %02d:%02d:%02d.%02d\n", year, month, day, hour, min, sec, cts); } else { snprintf(buf, 24, "%04d-%02d-%02d %02d:%02d:%02d.%02d", year, month, day, hour, min, sec, cts); av_metadata_set2(&s->metadata, "begin_date", buf, 0); av_metadata_set2(&module->metadata, "begin_date", buf, 0); } } day = get_byte(pb); month = get_byte(pb); year = get_be16(pb); hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (day || month || year || hour || min || sec || cts) { if (month == 0 || month > 12 || day == 0 || day > 31 || hour > 23 || min > 59 || sec > 59 || cts > 99) { av_log(module, AV_LOG_WARNING, "Invalid finish composing date: %04d-%02d-%02d %02d:%02d:%02d.%02d\n", year, month, day, hour, min, sec, cts); } else { snprintf(buf, 24, "%04d-%02d-%02d %02d:%02d:%02d.%02d", year, month, day, hour, min, sec, cts); av_metadata_set2(&s->metadata, "date", buf, 0); av_metadata_set2(&module->metadata, "date", buf, 0); } } hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (min > 59 || sec > 59 || cts > 99) { av_log(module, AV_LOG_WARNING, "Invalid duration: %02d:%02d:%02d.%02d\n", hour, min, sec, cts); } else { s->duration = (((uint64_t) (hour*360000+min*6000+sec*100+cts))*AV_TIME_BASE) / 100; module->forced_duration = (((uint64_t) (hour*360000+min*6000+sec*100+cts))*AV_TIME_BASE) / 100; } songs = get_be16(pb); tracks = get_be32(pb); instruments = get_be16(pb); samples = get_be32(pb); synths = get_be32(pb); envelopes = get_be16(pb); keyboards = get_be16(pb); arpeggios = get_be16(pb); avseq_module_set_channels(iff->avctx, module, get_be16(pb)); if (get_be16(pb)) { // compatibility flags and flags avsequencer_destroy(iff->avctx); return AVERROR_INVALIDDATA; } break; case ID_FORM: if (!module) break; switch (get_le32(pb)) { case ID_SONG: if ((res = open_tcm1_song(s, module, data_size)) < 0) { avsequencer_destroy(iff->avctx); return res; } break; case ID_INSL: if ((res = open_tcm1_insl(s, module, data_size)) < 0) { avsequencer_destroy(iff->avctx); return res; } break; case ID_ENVL: if ((res = open_tcm1_envl(s, module, data_size)) < 0) { avsequencer_destroy(iff->avctx); return res; } break; case ID_KEYB: if ((res = open_tcm1_keyb(s, module, data_size)) < 0) { avsequencer_destroy(iff->avctx); return res; } break; case ID_ARPL: if ((res = open_tcm1_arpl(s, module, data_size)) < 0) { avsequencer_destroy(iff->avctx); return res; } break; default: // TODO: Add unknown chunk break; } break; case ID_CMNT: case ID_MMSG: metadata_tag = "comment"; break; case ID_FILE: metadata_tag = "file"; break; case ID_STIL: metadata_tag = "genre"; break; #endif case ID_VHDR: #if CONFIG_AVSEQUENCER if (module) goto read_unknown_chunk; #endif st->codec->codec_type = AVMEDIA_TYPE_AUDIO; if (data_size < 14) return AVERROR_INVALIDDATA; url_fskip(pb, 12); st->codec->sample_rate = get_be16(pb); if (data_size >= 16) { url_fskip(pb, 1); compression = get_byte(pb); } break; case ID_BODY: #if CONFIG_AVSEQUENCER if (module) goto read_unknown_chunk; #endif iff->body_pos = url_ftell(pb); iff->body_size = data_size; break; case ID_CHAN: #if CONFIG_AVSEQUENCER if (module) goto read_unknown_chunk; #endif if (data_size < 4) return AVERROR_INVALIDDATA; st->codec->channels = (get_be32(pb) < 6) ? 1 : 2; break; case ID_CMAP: #if CONFIG_AVSEQUENCER if (module) goto read_unknown_chunk; #endif st->codec->extradata_size = data_size; st->codec->extradata = av_malloc(data_size); if (!st->codec->extradata) return AVERROR(ENOMEM); if (get_buffer(pb, st->codec->extradata, data_size) < 0) return AVERROR(EIO); break; case ID_BMHD: #if CONFIG_AVSEQUENCER if (module) goto read_unknown_chunk; #endif st->codec->codec_type = AVMEDIA_TYPE_VIDEO; if (data_size <= 8) return AVERROR_INVALIDDATA; st->codec->width = get_be16(pb); st->codec->height = get_be16(pb); url_fskip(pb, 4); // x, y offset st->codec->bits_per_coded_sample = get_byte(pb); if (data_size >= 11) { url_fskip(pb, 1); // masking compression = get_byte(pb); } if (data_size >= 16) { url_fskip(pb, 3); // paddding, transparent st->sample_aspect_ratio.num = get_byte(pb); st->sample_aspect_ratio.den = get_byte(pb); } break; case ID_ANNO: case ID_TEXT: metadata_tag = "comment"; break; case ID_AUTH: metadata_tag = "artist"; break; case ID_COPYRIGHT: metadata_tag = "copyright"; break; case ID_NAME: metadata_tag = "title"; break; #if CONFIG_AVSEQUENCER default: read_unknown_chunk: // TODO: Add unknown chunk break; #endif } if (metadata_tag) { if ((res = get_metadata(s, metadata_tag, data_size)) < 0) { #if CONFIG_AVSEQUENCER avsequencer_destroy(iff->avctx); #endif av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag); return res; } #if CONFIG_AVSEQUENCER if (module) { AVMetadataTag *tag = av_metadata_get(s->metadata, metadata_tag, NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) av_metadata_set2(&module->metadata, metadata_tag, tag->value, 0); } #endif } url_fskip(pb, data_size - (url_ftell(pb) - orig_pos) + (data_size & 1)); } url_fseek(pb, iff->body_pos, SEEK_SET); switch(st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: av_set_pts_info(st, 32, 1, st->codec->sample_rate); switch(compression) { case COMP_NONE: st->codec->codec_id = CODEC_ID_PCM_S8; break; case COMP_FIB: st->codec->codec_id = CODEC_ID_8SVX_FIB; break; case COMP_EXP: st->codec->codec_id = CODEC_ID_8SVX_EXP; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); return -1; } st->codec->bits_per_coded_sample = 8; #if CONFIG_AVSEQUENCER if (module) { AVMixerContext *mixctx; unsigned i; if (songs != module->songs) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached sub-songs does not match actual reads (expected: %d, got: %d)!\n", module->songs, songs); return AVERROR_INVALIDDATA; } if (instruments != module->instruments) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached instruments does not match actual reads (expected: %d, got: %d)!\n", module->instruments, instruments); return AVERROR_INVALIDDATA; } if (envelopes != module->envelopes) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached envelopes does not match actual reads (expected: %d, got: %d)!\n", module->envelopes, envelopes); return AVERROR_INVALIDDATA; } if (keyboards != module->keyboards) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached keyboard definitions does not match actual reads (expected: %d, got: %d)!\n", module->keyboards, keyboards); return AVERROR_INVALIDDATA; } if (arpeggios != module->arpeggios) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached arpeggio structures does not match actual reads (expected: %d, got: %d)!\n", module->arpeggios, arpeggios); return AVERROR_INVALIDDATA; } for (i = 0; i < module->songs; ++i) { uint16_t channel; AVSequencerSong *song = module->song_list[i]; AVSequencerOrderList *order_list = song->order_list; tracks -= song->tracks; for (channel = 0; channel < song->channels; ++channel) { uint16_t order; for (order = 0; order < order_list->orders; ++order) { AVSequencerOrderData *order_data = order_list->order_data[order]; order_data->track = avseq_track_get_address(song, (uint32_t) order_data->track); order_data->next_pos = avseq_order_get_address(song, channel, (uint32_t) order_data->next_pos); order_data->prev_pos = avseq_order_get_address(song, channel, (uint32_t) order_data->prev_pos); } order_list++; } } if (tracks) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached tracks does not match actual reads!\n"); return AVERROR_INVALIDDATA; } for (i = 0; i < module->instruments; ++i) { AVSequencerInstrument *instrument = module->instrument_list[i]; unsigned smp; instrument->volume_env = avseq_envelope_get_address(module, (uint32_t) instrument->volume_env); instrument->panning_env = avseq_envelope_get_address(module, (uint32_t) instrument->panning_env); instrument->slide_env = avseq_envelope_get_address(module, (uint32_t) instrument->slide_env); instrument->vibrato_env = avseq_envelope_get_address(module, (uint32_t) instrument->vibrato_env); instrument->tremolo_env = avseq_envelope_get_address(module, (uint32_t) instrument->tremolo_env); instrument->pannolo_env = avseq_envelope_get_address(module, (uint32_t) instrument->pannolo_env); instrument->channolo_env = avseq_envelope_get_address(module, (uint32_t) instrument->channolo_env); instrument->spenolo_env = avseq_envelope_get_address(module, (uint32_t) instrument->spenolo_env); instrument->arpeggio_ctrl = avseq_arpeggio_get_address(module, (uint32_t) instrument->arpeggio_ctrl); instrument->keyboard_defs = avseq_keyboard_get_address(module, (uint32_t) instrument->keyboard_defs); samples -= instrument->samples; for (smp = 0; smp < instrument->samples; ++smp) { AVSequencerSample *sample = instrument->sample_list[smp]; sample->auto_vibrato_env = avseq_envelope_get_address(module, (uint32_t) sample->auto_vibrato_env); sample->auto_tremolo_env = avseq_envelope_get_address(module, (uint32_t) sample->auto_tremolo_env); sample->auto_pannolo_env = avseq_envelope_get_address(module, (uint32_t) sample->auto_pannolo_env); if (sample->synth) synths--; if (sample->flags & AVSEQ_SAMPLE_FLAG_REDIRECT) { unsigned j; uint32_t origin = (uint32_t) sample->data; for (j = 0; j < module->instruments; ++j) { AVSequencerInstrument *origin_instrument = module->instrument_list[i]; if (origin < origin_instrument->samples) sample->data = origin_instrument->sample_list[origin]->data; origin -= origin_instrument->samples; } } } } if (samples) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached samples does not match actual reads!\n"); return AVERROR_INVALIDDATA; } if (synths) { avsequencer_destroy(iff->avctx); av_log(module, AV_LOG_ERROR, "Number of attached synths does not match actual reads!\n"); return AVERROR_INVALIDDATA; } if (songs == 1) { for (i = 0; i < sizeof (metadata_tag_list) / sizeof (char *); ++i) { const char *metadata_tag = metadata_tag_list[i]; AVMetadataTag *tag = av_metadata_get(s->metadata, metadata_tag, NULL, AV_METADATA_IGNORE_SUFFIX); if (!tag) { tag = av_metadata_get(module->song_list[0]->metadata, metadata_tag, NULL, AV_METADATA_IGNORE_SUFFIX); if (tag) av_metadata_set2(&s->metadata, metadata_tag, tag->value, 0); } } } if (!(mixctx = avseq_mixer_get_by_name("High quality mixer"))) { if (!(mixctx = avseq_mixer_get_by_name("Low quality mixer"))) { if (!(mixctx = avseq_mixer_get_by_name("Null mixer"))) { avsequencer_destroy(iff->avctx); av_log(s, AV_LOG_ERROR, "No mixers found!\n"); return AVERROR(ENOMEM); } } } if (!(st->codec->sample_rate = ap->sample_rate)) st->codec->sample_rate = mixctx->frequency; if (!(st->codec->channels = ap->channels)) st->codec->channels = mixctx->channels_out; iff->body_size = ((uint64_t) s->duration * st->codec->sample_rate * (st->codec->channels << 2)) / AV_TIME_BASE; + avseq_module_set_channels(iff->avctx, module, 64); if ((res = avseq_module_play(iff->avctx, mixctx, module, module->song_list[0], iff->args, iff->opaque, 1)) < 0) { avsequencer_destroy(iff->avctx); return res; } avseq_mixer_set_rate(iff->avctx->player_mixer_data, st->codec->sample_rate, st->codec->channels); if ((res = avseq_song_reset(iff->avctx, module->song_list[0])) < 0) { avsequencer_destroy(iff->avctx); return res; } // iff->avctx->seed = 0xFA1E1E51; // FATE test init seed st->codec->bits_per_coded_sample = 32; #if AV_HAVE_BIGENDIAN st->codec->codec_id = CODEC_ID_PCM_S32BE; #else st->codec->codec_id = CODEC_ID_PCM_S32LE; #endif } #endif st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; break; case AVMEDIA_TYPE_VIDEO: switch (compression) { case BITMAP_RAW: st->codec->codec_id = CODEC_ID_IFF_ILBM; break; case BITMAP_BYTERUN1: st->codec->codec_id = CODEC_ID_IFF_BYTERUN1; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); return AVERROR_INVALIDDATA; } break; default: return -1; } return 0; } #if CONFIG_AVSEQUENCER /* Metadata string read */ static int seq_get_metadata(AVFormatContext *s, AVMetadata **const metadata, const char *const tag, const unsigned data_size) { uint8_t *buf = ((data_size + 1) == 0) ? NULL : av_malloc(data_size + 1); if (!buf) return AVERROR(ENOMEM); if (get_buffer(s->pb, buf, data_size) < 0) { av_free(buf); return AVERROR(EIO); } buf[data_size] = 0; av_metadata_set2(metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); return 0; } static int open_tcm1_song(AVFormatContext *s, AVSequencerModule *module, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerSong *song; IffDemuxContext *iff = s->priv_data; uint32_t iff_size = 4; uint16_t tracks = 0, channels = 1; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; if (!(song = avseq_song_create())) return AVERROR(ENOMEM); if ((res = avseq_song_open(module, song)) < 0) { avseq_song_destroy(song); return res; } avseq_song_set_channels(iff->avctx, song, 1); while (!url_feof(pb) && (data_size -= iff_size)) { unsigned year, month, day, hour, min, sec, cts; uint8_t buf[24]; uint64_t orig_pos; uint32_t chunk_id; const char *metadata_tag = NULL; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_SHDR: day = get_byte(pb); month = get_byte(pb); year = get_be16(pb); hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (day || month || year || hour || min || sec || cts) { if (month == 0 || month > 12 || day == 0 || day > 31 || hour > 23 || min > 59 || sec > 59 || cts > 99) { av_log(song, AV_LOG_WARNING, "Invalid begin composing date: %04d-%02d-%02d %02d:%02d:%02d.%02d\n", year, month, day, hour, min, sec, cts); } else { snprintf(buf, 24, "%04d-%02d-%02d %02d:%02d:%02d.%02d", year, month, day, hour, min, sec, cts ); av_metadata_set2(&song->metadata, "begin_date", buf, 0); } } day = get_byte(pb); month = get_byte(pb); year = get_be16(pb); hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (day || month || year || hour || min || sec || cts) { if (month == 0 || month > 12 || day == 0 || day > 31 || hour > 23 || min > 59 || sec > 59 || cts > 99) { av_log(song, AV_LOG_WARNING, "Invalid finish composing date: %04d-%02d-%02d %02d:%02d:%02d.%02d\n", year, month, day, hour, min, sec, cts); } else { snprintf(buf, 24, "%04d-%02d-%02d %02d:%02d:%02d.%02d", year, month, day, hour, min, sec, cts ); av_metadata_set2(&song->metadata, "date", buf, 0); } } hour = get_byte(pb); min = get_byte(pb); sec = get_byte(pb); cts = get_byte(pb); if (min > 59 || sec > 59 || cts > 99) av_log(song, AV_LOG_WARNING, "Invalid duration: %02d:%02d:%02d.%02d\n", hour, min, sec, cts); else song->duration = (((uint64_t) (hour*360000+min*6000+sec*100+cts))*AV_TIME_BASE) / 100; tracks = get_be16(pb); song->gosub_stack_size = get_be16(pb); song->loop_stack_size = get_be16(pb); song->compat_flags = get_byte(pb); song->flags = get_byte(pb); channels = get_be16(pb); song->frames = get_be16(pb); song->speed_mul = get_byte(pb); song->speed_div = get_byte(pb); song->spd_speed = get_be16(pb); song->bpm_tempo = get_be16(pb); song->bpm_speed = get_be16(pb); song->frames_min = get_be16(pb); song->frames_max = get_be16(pb); song->spd_min = get_be16(pb); song->spd_max = get_be16(pb); song->bpm_tempo_min = get_be16(pb); song->bpm_tempo_max = get_be16(pb); song->bpm_speed_min = get_be16(pb); song->bpm_speed_max = get_be16(pb); song->global_volume = get_byte(pb); song->global_sub_volume = get_byte(pb); song->global_panning = get_byte(pb); song->global_sub_panning = get_byte(pb); if ((res = avseq_song_set_channels(iff->avctx, song, channels)) < 0) return res; break; case ID_FORM: switch (get_le32(pb)) { case ID_PATT: if ((res = open_song_patt(s, song, iff_size)) < 0) return res; break; case ID_POSI: if ((res = open_song_posi(s, song, iff_size)) < 0) return res; break; default: // TODO: Add unknown chunk break; } break; case ID_ANNO: case ID_CMNT: case ID_SMSG: case ID_TEXT: metadata_tag = "comment"; break; case ID_AUTH: metadata_tag = "artist"; break; case ID_COPYRIGHT: metadata_tag = "copyright"; break; case ID_FILE: metadata_tag = "file"; break; case ID_STIL: metadata_tag = "genre"; break; case ID_NAME: metadata_tag = "title"; break; default: // TODO: Add unknown chunk break; } if (metadata_tag) { if ((res = seq_get_metadata(s, &song->metadata, metadata_tag, iff_size)) < 0) { av_log(song, AV_LOG_ERROR, "Cannot allocate metadata tag %s!\n", metadata_tag); return res; } } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if (tracks != song->tracks) { av_log(song, AV_LOG_ERROR, "Number of attached tracks does not match actual reads (expected: %d, got: %d)!\n", song->tracks, tracks); return AVERROR_INVALIDDATA; } if (channels != song->channels) { av_log(song, AV_LOG_ERROR, "Number of attached channels does not match actual reads (expected: %d, got: %d)!\n", song->channels, channels); return AVERROR_INVALIDDATA; } return 0; } static int open_song_patt(AVFormatContext *s, AVSequencerSong *song, uint32_t data_size) { ByteIOContext *pb = s->pb; uint32_t iff_size = 4; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_FORM: switch (get_le32(pb)) { case ID_TRAK: if ((res = open_patt_trak(s, song, iff_size)) < 0) return res; break; } break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } return 0; } static int open_patt_trak(AVFormatContext *s, AVSequencerSong *song, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerTrack *track; uint8_t *buf = NULL; uint32_t last_row = 0, len = 0, iff_size = 4; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; if (!(track = avseq_track_create())) return AVERROR(ENOMEM); if ((res = avseq_track_open(song, track)) < 0) { avseq_track_destroy(track); return res; } while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; const char *metadata_tag = NULL; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_THDR: last_row = get_be16(pb); track->volume = get_byte(pb); track->sub_volume = get_byte(pb); track->panning = get_byte(pb); track->sub_panning = get_byte(pb); track->transpose = get_byte(pb); track->compat_flags = get_byte(pb); track->flags = get_be16(pb); track->frames = get_be16(pb); track->speed_mul = get_byte(pb); track->speed_div = get_byte(pb); track->spd_speed = get_be16(pb); track->bpm_tempo = get_be16(pb); track->bpm_speed = get_be16(pb); break; case ID_BODY: len = iff_size; buf = av_malloc(iff_size + 1 + FF_INPUT_BUFFER_PADDING_SIZE); if (!buf) return AVERROR(ENOMEM); if (get_buffer(pb, buf, iff_size) < 0) { av_freep(&buf); return AVERROR(EIO); } buf[iff_size] = 0; break; case ID_ANNO: case ID_TEXT: metadata_tag = "comment"; break; case ID_AUTH: metadata_tag = "artist"; break; case ID_COPYRIGHT: metadata_tag = "copyright"; break; case ID_FILE: metadata_tag = "file"; break; case ID_NAME: metadata_tag = "title"; break; default: // TODO: Add unknown chunk break; } if (metadata_tag) { if ((res = seq_get_metadata(s, &track->metadata, metadata_tag, iff_size)) < 0) { av_freep(&buf); av_log(track, AV_LOG_ERROR, "Cannot allocate metadata tag %s!\n", metadata_tag); return res; } } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } if ((res = avseq_track_data_open(track, last_row + 1)) < 0) { av_freep(&buf); return res; } if (buf && len) { if ((res = avseq_track_unpack(track, buf, len)) < 0) { av_freep(&buf); return res; } } av_freep(&buf); return 0; } static int open_song_posi(AVFormatContext *s, AVSequencerSong *song, uint32_t data_size) { ByteIOContext *pb = s->pb; IffDemuxContext *iff = s->priv_data; uint32_t iff_size = 4, channel = 0; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_FORM: switch (get_le32(pb)) { case ID_POST: if (channel >= song->channels) { if ((res = avseq_song_set_channels(iff->avctx, song, channel + 1)) < 0) return res; } if ((res = open_posi_post(s, song, channel++, iff_size)) < 0) return res; break; } break; } iff_size += iff_size & 1; url_fskip(pb, iff_size - (url_ftell(pb) - orig_pos)); iff_size += 8; } return 0; } static int open_posi_post(AVFormatContext *s, AVSequencerSong *song, uint32_t channel, uint32_t data_size) { ByteIOContext *pb = s->pb; AVSequencerOrderList *order_list = song->order_list + channel; uint32_t iff_size = 4; int res; if (data_size < 4) return AVERROR_INVALIDDATA; data_size += data_size & 1; while (!url_feof(pb) && (data_size -= iff_size)) { uint64_t orig_pos; uint32_t chunk_id; const char *metadata_tag = NULL; chunk_id = get_le32(pb); iff_size = get_be32(pb); orig_pos = url_ftell(pb); switch(chunk_id) { case ID_PHDR: order_list->length = get_be16(pb); order_list->rep_start = get_be16(pb); order_list->volume = get_byte(pb); order_list->sub_volume = get_byte(pb); order_list->track_panning = get_byte(pb); order_list->track_sub_panning = get_byte(pb); order_list->channel_panning = get_byte(pb); order_list->channel_sub_panning = get_byte(pb); if (get_byte(pb)) // compatibility flags return AVERROR_INVALIDDATA; order_list->flags = get_byte(pb); break; case ID_FORM: switch (get_le32(pb)) { case ID_POSL: if ((res = open_post_posl(s, order_list, iff_size)) < 0) return res; break; default: // TODO: Add unknown chunk break; } break; diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index c5e8ada..36cdd78 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -3644,1009 +3644,1009 @@ static void set_mix_functions(const AV_HQMixerData *const mixer_data, struct Cha if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left_16_to_8; break; case 0xFF : mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } static void update_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } static void set_sample_filter(const AV_HQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_HQMixerData *hq_mixer_data; AV_HQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned real16bit = 1, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(hq_mixer_data = av_mallocz(sizeof(AV_HQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(hq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mixer_data.mixctx = mixctx; buf_size = hq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=false;") || av_stristr(args, "real16bit=disabled;")) real16bit = 0; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->channel_info = channel_info; hq_mixer_data->mixer_data.channels_in = channels_in; hq_mixer_data->channels_in = channels_in; hq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->mix_buf_size = mix_buf_mem_size; hq_mixer_data->buf = buf; hq_mixer_data->buf_size = buf_size; hq_mixer_data->mixer_data.mix_buf_size = hq_mixer_data->buf_size; hq_mixer_data->mixer_data.mix_buf = hq_mixer_data->buf; channel_rate = hq_mixer_data->mixer_data.mixctx->frequency; hq_mixer_data->mixer_data.rate = channel_rate; hq_mixer_data->mix_rate = channel_rate; hq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_free(hq_mixer_data); return NULL; } hq_mixer_data->filter_buf = buf; for (i = hq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) hq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_HQMixerData *hq_mixer_data = (AV_HQMixerData *) mixer_data; if (!hq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&hq_mixer_data->channel_info); av_freep(&hq_mixer_data->volume_lut); av_freep(&hq_mixer_data->buf); av_freep(&hq_mixer_data->filter_buf); av_free(hq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t channel_rate = hq_mixer_data->mix_rate * 10; uint64_t pass_value; hq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) hq_mixer_data->mix_rate_frac >> 16); hq_mixer_data->pass_len = (uint64_t) pass_value / hq_mixer_data->mixer_data.tempo; hq_mixer_data->pass_len_frac = (((uint64_t) pass_value % hq_mixer_data->mixer_data.tempo) << 32) / hq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; hq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = hq_mixer_data->mixer_data.mix_buf_size; hq_mixer_data->mixer_data.channels_out = new_channels; if ((hq_mixer_data->buf_size * hq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = hq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = hq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return hq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return hq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); hq_mixer_data->mixer_data.mix_buf = buf; hq_mixer_data->mixer_data.mix_buf_size = buf_size; hq_mixer_data->filter_buf = filter_buf; } hq_mixer_data->channels_out = new_channels; hq_mixer_data->buf = hq_mixer_data->mixer_data.mix_buf; hq_mixer_data->buf_size = hq_mixer_data->mixer_data.mix_buf_size; if (hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (hq_mixer_data->mix_rate != mix_rate) { AV_HQMixerChannelInfo *channel_info = hq_mixer_data->channel_info; uint16_t i; hq_mixer_data->mix_rate = mix_rate; hq_mixer_data->mix_rate_frac = mix_rate_frac; if (hq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, hq_mixer_data->mixer_data.tempo); for (i = hq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; update_sample_filter(hq_mixer_data, &channel_info->current); update_sample_filter(hq_mixer_data, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *channel_info = NULL; AV_HQMixerChannelInfo *const old_channel_info = hq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = hq_mixer_data->channels_in) != channels) && (!(channel_info = av_mallocz((channels * sizeof(AV_HQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE)))) { av_log(hq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } hq_mixer_data->mixer_data.volume_boost = amplify; hq_mixer_data->mixer_data.volume_left = left_volume; hq_mixer_data->mixer_data.volume_right = right_volume; hq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (hq_mixer_data->amplify != amplify)) { - int32_t *volume_lut = hq_mixer_data->volume_lut; - uint32_t volume_mult = 0, volume_div = channels << 8; - uint8_t i = 0, j = 0; + int32_t *volume_lut = hq_mixer_data->volume_lut; + int32_t volume_mult = 0, volume_div = channels << 8; + uint8_t i = 0, j = 0; hq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; - *volume_lut++ = (int64_t) volume * volume_mult / volume_div; + *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_HQMixerChannelInfo)); hq_mixer_data->channel_info = channel_info; hq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(hq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(hq_mixer_data, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = hq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(hq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_filter(hq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; set_sample_filter(hq_mixer_data, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; channel_info->prev_sample = 0; channel_info->curr_sample = 0; channel_info->next_sample = 0; set_sample_filter(hq_mixer_data, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; const AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_filter(hq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; set_sample_filter(hq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); set_sample_mix_rate(hq_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = hq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(hq_mixer_data, &channel_info->current); set_mix_functions(hq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(hq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; AV_HQMixerChannelInfo *const channel_info = hq_mixer_data->channel_info + channel; set_sample_filter(hq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_HQMixerData *const hq_mixer_data = (AV_HQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(hq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = hq_mixer_data->mix_rate; current_left = hq_mixer_data->current_left; current_left_frac = hq_mixer_data->current_left_frac; buf_size = hq_mixer_data->buf_size; memset(buf, 0, buf_size << ((hq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(hq_mixer_data, buf, mix_len); buf += (hq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = hq_mixer_data->pass_len; current_left_frac += hq_mixer_data->pass_len_frac; if (current_left_frac < hq_mixer_data->pass_len_frac) current_left++; } hq_mixer_data->current_left = current_left; hq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext high_quality_mixer = { .av_class = &avseq_high_quality_mixer_class, .name = "High quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for quality and supports advanced interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, }; #endif /* CONFIG_HIGH_QUALITY_MIXER */ diff --git a/libavsequencer/lq_mixer.c b/libavsequencer/lq_mixer.c index 6f0c8df..96e01f3 100644 --- a/libavsequencer/lq_mixer.c +++ b/libavsequencer/lq_mixer.c @@ -3285,1005 +3285,1005 @@ static void set_mix_functions(const AV_LQMixerData *const mixer_data, struct Cha mix_func = (void *) &mixer_skip_16_to_8; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right_16_to_8; break; case 0x80 : mix_func = (void *) &mixer_stereo_16_to_8; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center_16_to_8; break; default : mix_func = (void *) &mixer_stereo_16_to_8; break; } } } else if ((channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_MUTED) || !channel_block->volume || !mixer_data->amplify || !channel_block->data) { mix_func = (void *) &mixer_skip; } else if (mixer_data->channels_out <= 1) { mix_func = (void *) &mixer_mono; } else if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_SURROUND) { mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_surround; } else { switch ((panning = channel_block->panning)) { case 0 : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_left) mix_func = (void *) &mixer_stereo_left; break; case 0xFF : mix_func = (void *) &mixer_skip; if (mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_right; break; case 0x80 : mix_func = (void *) &mixer_stereo; if (mixer_data->mixer_data.volume_left == mixer_data->mixer_data.volume_right) mix_func = (void *) &mixer_stereo_center; break; default : mix_func = (void *) &mixer_stereo; break; } } switch (channel_block->bits_per_sample) { case 8 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[7]; channel_block->mix_backwards_func = (void *) mix_func[3]; } else { channel_block->mix_func = (void *) mix_func[3]; channel_block->mix_backwards_func = (void *) mix_func[7]; } init_mixer_func = (void *) mix_func[0]; break; case 16 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[8]; channel_block->mix_backwards_func = (void *) mix_func[4]; } else { channel_block->mix_func = (void *) mix_func[4]; channel_block->mix_backwards_func = (void *) mix_func[8]; } init_mixer_func = (void *) mix_func[1]; break; case 32 : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[9]; channel_block->mix_backwards_func = (void *) mix_func[5]; } else { channel_block->mix_func = (void *) mix_func[5]; channel_block->mix_backwards_func = (void *) mix_func[9]; } init_mixer_func = (void *) mix_func[2]; break; default : if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { channel_block->mix_func = (void *) mix_func[10]; channel_block->mix_backwards_func = (void *) mix_func[6]; } else { channel_block->mix_func = (void *) mix_func[6]; channel_block->mix_backwards_func = (void *) mix_func[10]; } init_mixer_func = (void *) mix_func[2]; break; } init_mixer_func(mixer_data, channel_block, channel_block->volume, panning); } static void set_sample_mix_rate(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, const uint32_t rate) { const uint32_t mix_rate = mixer_data->mix_rate; channel_block->rate = rate; channel_block->advance = rate / mix_rate; channel_block->advance_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; set_mix_functions(mixer_data, channel_block); } // TODO: Implement low quality mixer identification and configuration. /** Filter natural frequency table. Value is (2*PI*110*(2^0.25)*2^(x/24))*(2^24). */ static const int64_t nat_freq_lut[] = { INT64_C( 13789545379), INT64_C( 14193609901), INT64_C( 14609514417), INT64_C( 15037605866), INT64_C( 15478241352), INT64_C( 15931788442), INT64_C( 16398625478), INT64_C( 16879141882), INT64_C( 17373738492), INT64_C( 17882827888), INT64_C( 18406834743), INT64_C( 18946196171), INT64_C( 19501362094), INT64_C( 20072795621), INT64_C( 20660973429), INT64_C( 21266386161), INT64_C( 21889538841), INT64_C( 22530951288), INT64_C( 23191158555), INT64_C( 23870711371), INT64_C( 24570176604), INT64_C( 25290137733), INT64_C( 26031195334), INT64_C( 26793967580), INT64_C( 27579090758), INT64_C( 28387219802), INT64_C( 29219028834), INT64_C( 30075211732), INT64_C( 30956482703), INT64_C( 31863576885), INT64_C( 32797250955), INT64_C( 33758283764), INT64_C( 34747476983), INT64_C( 35765655777), INT64_C( 36813669486), INT64_C( 37892392341), INT64_C( 39002724188), INT64_C( 40145591242), INT64_C( 41321946857), INT64_C( 42532772322), INT64_C( 43779077682), INT64_C( 45061902576), INT64_C( 46382317109), INT64_C( 47741422741), INT64_C( 49140353208), INT64_C( 50580275467), INT64_C( 52062390668), INT64_C( 53587935159), INT64_C( 55158181517), INT64_C( 56774439604), INT64_C( 58438057669), INT64_C( 60150423464), INT64_C( 61912965406), INT64_C( 63727153770), INT64_C( 65594501910), INT64_C( 67516567528), INT64_C( 69494953967), INT64_C( 71531311553), INT64_C( 73627338972), INT64_C( 75784784682), INT64_C( 78005448377), INT64_C( 80291182485), INT64_C( 82643893714), INT64_C( 85065544645), INT64_C( 87558155364), INT64_C( 90123805153), INT64_C( 92764634219), INT64_C( 95482845483), INT64_C( 98280706416), INT64_C(101160550933), INT64_C(104124781336), INT64_C(107175870319), INT64_C(110316363033), INT64_C(113548879209), INT64_C(116876115338), INT64_C(120300846927), INT64_C(123825930812), INT64_C(127454307540), INT64_C(131189003821), INT64_C(135033135055), INT64_C(138989907934), INT64_C(143062623107), INT64_C(147254677944), INT64_C(151569569364), INT64_C(156010896753), INT64_C(160582364969), INT64_C(165287787428), INT64_C(170131089290), INT64_C(175116310728), INT64_C(180247610306), INT64_C(185529268437), INT64_C(190965690965), INT64_C(196561412833), INT64_C(202321101866), INT64_C(208249562671), INT64_C(214351740638), INT64_C(220632726067), INT64_C(227097758417), INT64_C(233752230676), INT64_C(240601693855), INT64_C(247651861625), INT64_C(254908615079), INT64_C(262378007641), INT64_C(270066270111), INT64_C(277979815867), INT64_C(286125246214), INT64_C(294509355888), INT64_C(303139138728), INT64_C(312021793507), INT64_C(321164729938), INT64_C(330575574856), INT64_C(340262178579), INT64_C(350232621457), INT64_C(360495220611), INT64_C(371058536874), INT64_C(381931381930), INT64_C(393122825665), INT64_C(404642203733), INT64_C(416499125343), INT64_C(428703481275), INT64_C(441265452133), INT64_C(454195516834), INT64_C(467504461351), INT64_C(481203387710), INT64_C(495303723250), INT64_C(509817230159), INT64_C(524756015282), INT64_C(540132540222) }; /** Filter damping factor table. Value is 2*10^(-((24/128)*x)/20)*(2^24). */ static const int32_t damp_factor_lut[] = { 33554432, 32837863, 32136597, 31450307, 30778673, 30121382, 29478127, 28848610, 28232536, 27629619, 27039577, 26462136, 25897026, 25343984, 24802753, 24273080, 23754719, 23247427, 22750969, 22265112, 21789632, 21324305, 20868916, 20423252, 19987105, 19560272, 19142554, 18733757, 18333690, 17942167, 17559005, 17184025, 16817053, 16457918, 16106452, 15762492, 15425878, 15096452, 14774061, 14458555, 14149787, 13847612, 13551891, 13262485, 12979259, 12702081, 12430823, 12165358, 11905562, 11651314, 11402495, 11158990, 10920685, 10687470, 10459234, 10235873, 10017282, 9803359, 9594004, 9389120, 9188612, 8992385, 8800349, 8612414, 8428492, 8248498, 8072348, 7899960, 7731253, 7566149, 7404571, 7246443, 7091692, 6940246, 6792035, 6646988, 6505039, 6366121, 6230170, 6097122, 5966916, 5839490, 5714785, 5592743, 5473308, 5356423, 5242035, 5130089, 5020534, 4913318, 4808392, 4705707, 4605215, 4506869, 4410623, 4316432, 4224253, 4134042, 4045758, 3959359, 3874805, 3792057, 3711076, 3631825, 3554266, 3478363, 3404081, 3331386, 3260242, 3190619, 3122482, 3055800, 2990542, 2926678, 2864177, 2803012, 2743152, 2684571, 2627241, 2571135, 2516227, 2462492, 2409905, 2358440, 2308075, 2258785, 2210548, 2163341 }; static inline void mulu_128(uint64_t *result, const uint64_t a, const uint64_t b) { const uint32_t a_hi = a >> 32; const uint32_t a_lo = (uint32_t) a; const uint32_t b_hi = b >> 32; const uint32_t b_lo = (uint32_t) b; uint64_t x0 = (uint64_t) a_hi * b_hi; uint64_t x1 = (uint64_t) a_lo * b_hi; uint64_t x2 = (uint64_t) a_hi * b_lo; uint64_t x3 = (uint64_t) a_lo * b_lo; x2 += x3 >> 32; x2 += x1; if (x2 < x1) x0 += UINT64_C(0x100000000); *result++ = x0 + (x2 >> 32); *result = ((x2 & UINT64_C(0xFFFFFFFF)) << 32) + (x3 & UINT64_C(0xFFFFFFFF)); } static inline void muls_128(int64_t *result, const int64_t a, const int64_t b) { int sign = (a ^ b) < 0; mulu_128(result, a < 0 ? -a : a, b < 0 ? -b : b ); if (sign) *result = -(*result); } static inline uint64_t divu_128(uint64_t a_hi, uint64_t a_lo, const uint64_t b) { uint64_t result = 0, result_r = 0; uint16_t i = 128; while (i--) { const uint64_t carry = a_lo >> 63; const uint64_t carry2 = a_hi >> 63; result <<= 1; a_lo <<= 1; a_hi = (((a_hi << 1) | (a_hi >> 63)) & ~UINT64_C(1)) | carry; // simulate bitwise rotate with extend (carry) result_r = (((result_r << 1) | (result_r >> 63)) & ~UINT64_C(1)) | carry2; // simulate bitwise rotate with extend (carry) if (result_r >= b) { result_r -= b; result++; } } return result; } static inline int64_t divs_128(int64_t a_hi, uint64_t a_lo, const int64_t b) { int sign = (a_hi ^ b) < 0; int64_t result = divu_128(a_hi < 0 ? -a_hi : a_hi, a_lo, b < 0 ? -b : b ); if (sign) result = -result; return result; } static void update_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block) { const uint32_t mix_rate = mixer_data->mix_rate; uint64_t tmp_128[2]; int64_t nat_freq, damp_factor, d, e, tmp; if ((channel_block->filter_cutoff == 127) && (channel_block->filter_damping == 0)) { channel_block->filter_c1 = 16777216; channel_block->filter_c2 = 0; channel_block->filter_c3 = 0; return; } nat_freq = nat_freq_lut[channel_block->filter_cutoff]; damp_factor = damp_factor_lut[channel_block->filter_damping]; d = (nat_freq * (INT64_C(16777216) - damp_factor)) / ((int64_t) mix_rate << 24); if (d > INT64_C(33554432)) d = INT64_C(33554432); muls_128(tmp_128, damp_factor - d, (int64_t) mix_rate << 24); d = divs_128(tmp_128[0], tmp_128[1], nat_freq); mulu_128(tmp_128, (uint64_t) mix_rate << 29, (uint64_t) mix_rate << 29); // Using more than 58 (2*29) bits in total will result in 128-bit integer multiply overflow for maximum allowed mixing rate of 768kHz e = (divu_128(tmp_128[0], tmp_128[1], nat_freq) / nat_freq) << 14; tmp = INT64_C(16777216) + d + e; channel_block->filter_c1 = (int32_t) (INT64_C(281474976710656) / tmp); channel_block->filter_c2 = (int32_t) (((d + e + e) << 24) / tmp); channel_block->filter_c3 = (int32_t) (((-e) << 24) / tmp); } static void set_sample_filter(const AV_LQMixerData *const mixer_data, struct ChannelBlock *const channel_block, uint8_t cutoff, uint8_t damping) { if ((int8_t) cutoff < 0) cutoff = 127; if ((int8_t) damping < 0) damping = 127; if ((channel_block->filter_cutoff == cutoff) && (channel_block->filter_damping == damping)) return; channel_block->filter_cutoff = cutoff; channel_block->filter_damping = damping; update_sample_filter(mixer_data, channel_block); } static av_cold AVMixerData *init(AVMixerContext *mixctx, const char *args, void *opaque) { AV_LQMixerData *lq_mixer_data; AV_LQMixerChannelInfo *channel_info; const char *cfg_buf; uint16_t i; int32_t *buf; unsigned interpolation = 0, real16bit = 0, buf_size; uint32_t mix_buf_mem_size, channel_rate; uint16_t channels_in = 1, channels_out = 1; if (!(lq_mixer_data = av_mallocz(sizeof(AV_LQMixerData) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer data factory.\n"); return NULL; } if (!(lq_mixer_data->volume_lut = av_malloc((256 * 256 * sizeof(int32_t)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer volume lookup table.\n"); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mixer_data.mixctx = mixctx; buf_size = lq_mixer_data->mixer_data.mixctx->buf_size; if ((cfg_buf = av_stristr(args, "buffer="))) sscanf(cfg_buf, "buffer=%d;", &buf_size); if (av_stristr(args, "real16bit=true;") || av_stristr(args, "real16bit=enabled;")) real16bit = 1; else if ((cfg_buf = av_stristr(args, "real16bit=;"))) sscanf(cfg_buf, "real16bit=%d;", &real16bit); if (av_stristr(args, "interpolation=true;") || av_stristr(args, "interpolation=enabled;")) interpolation = 2; else if ((cfg_buf = av_stristr(args, "interpolation="))) sscanf(cfg_buf, "interpolation=%d;", &interpolation); if (!(channel_info = av_mallocz((channels_in * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->channel_info = channel_info; lq_mixer_data->mixer_data.channels_in = channels_in; lq_mixer_data->channels_in = channels_in; lq_mixer_data->channels_out = channels_out; mix_buf_mem_size = (buf_size << 2) * channels_out; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->mix_buf_size = mix_buf_mem_size; lq_mixer_data->buf = buf; lq_mixer_data->buf_size = buf_size; lq_mixer_data->mixer_data.mix_buf_size = lq_mixer_data->buf_size; lq_mixer_data->mixer_data.mix_buf = lq_mixer_data->buf; channel_rate = lq_mixer_data->mixer_data.mixctx->frequency; lq_mixer_data->mixer_data.rate = channel_rate; lq_mixer_data->mix_rate = channel_rate; lq_mixer_data->real_16_bit_mode = real16bit ? 1 : 0; lq_mixer_data->interpolation = interpolation >= 2 ? 2 : interpolation; if (!(buf = av_mallocz(mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_free(lq_mixer_data); return NULL; } lq_mixer_data->filter_buf = buf; for (i = lq_mixer_data->channels_in; i > 0; i--) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } return (AVMixerData *) lq_mixer_data; } static av_cold int uninit(AVMixerData *mixer_data) { AV_LQMixerData *lq_mixer_data = (AV_LQMixerData *) mixer_data; if (!lq_mixer_data) return AVERROR_INVALIDDATA; av_freep(&lq_mixer_data->channel_info); av_freep(&lq_mixer_data->volume_lut); av_freep(&lq_mixer_data->buf); av_freep(&lq_mixer_data->filter_buf); av_free(lq_mixer_data); return 0; } static av_cold uint32_t set_tempo(AVMixerData *mixer_data, uint32_t new_tempo) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t channel_rate = lq_mixer_data->mix_rate * 10; uint64_t pass_value; lq_mixer_data->mixer_data.tempo = new_tempo; pass_value = ((uint64_t) channel_rate << 16) + ((uint64_t) lq_mixer_data->mix_rate_frac >> 16); lq_mixer_data->pass_len = (uint64_t) pass_value / lq_mixer_data->mixer_data.tempo; lq_mixer_data->pass_len_frac = (((uint64_t) pass_value % lq_mixer_data->mixer_data.tempo) << 32) / lq_mixer_data->mixer_data.tempo; return new_tempo; } static av_cold uint32_t set_rate(AVMixerData *mixer_data, uint32_t new_mix_rate, uint32_t new_channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t buf_size, mix_rate, mix_rate_frac; lq_mixer_data->mixer_data.rate = new_mix_rate; buf_size = lq_mixer_data->mixer_data.mix_buf_size; lq_mixer_data->mixer_data.channels_out = new_channels; if ((lq_mixer_data->buf_size * lq_mixer_data->channels_out) != (buf_size * new_channels)) { int32_t *buf = lq_mixer_data->mixer_data.mix_buf; int32_t *filter_buf = lq_mixer_data->filter_buf; const uint32_t mix_buf_mem_size = (buf_size * new_channels) << 2; if (!(buf = av_realloc(buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer output buffer.\n"); return lq_mixer_data->mixer_data.rate; } else if (!(filter_buf = av_realloc(filter_buf, mix_buf_mem_size + FF_INPUT_BUFFER_PADDING_SIZE))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer (resonance) filter output buffer.\n"); return lq_mixer_data->mixer_data.rate; } memset(buf, 0, mix_buf_mem_size); lq_mixer_data->mixer_data.mix_buf = buf; lq_mixer_data->mixer_data.mix_buf_size = buf_size; lq_mixer_data->filter_buf = filter_buf; } lq_mixer_data->channels_out = new_channels; lq_mixer_data->buf = lq_mixer_data->mixer_data.mix_buf; lq_mixer_data->buf_size = lq_mixer_data->mixer_data.mix_buf_size; if (lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_MIXING) { mix_rate = new_mix_rate; // TODO: Add check here if this mix rate is supported by target device mix_rate_frac = 0; if (lq_mixer_data->mix_rate != mix_rate) { AV_LQMixerChannelInfo *channel_info = lq_mixer_data->channel_info; uint16_t i; lq_mixer_data->mix_rate = mix_rate; lq_mixer_data->mix_rate_frac = mix_rate_frac; if (lq_mixer_data->mixer_data.tempo) set_tempo((AVMixerData *) mixer_data, lq_mixer_data->mixer_data.tempo); for (i = lq_mixer_data->channels_in; i > 0; i--) { channel_info->current.advance = channel_info->current.rate / mix_rate; channel_info->current.advance_frac = (((uint64_t) channel_info->current.rate % mix_rate) << 32) / mix_rate; channel_info->next.advance = channel_info->next.rate / mix_rate; channel_info->next.advance_frac = (((uint64_t) channel_info->next.rate % mix_rate) << 32) / mix_rate; update_sample_filter(lq_mixer_data, &channel_info->current); update_sample_filter(lq_mixer_data, &channel_info->next); channel_info++; } } } // TODO: Inform libavfilter that the target mixing rate has been changed. return new_mix_rate; } static av_cold uint32_t set_volume(AVMixerData *mixer_data, uint32_t amplify, uint32_t left_volume, uint32_t right_volume, uint32_t channels) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *channel_info = NULL; AV_LQMixerChannelInfo *const old_channel_info = lq_mixer_data->channel_info; uint32_t old_channels, i; if (((old_channels = lq_mixer_data->channels_in) != channels) && (!(channel_info = av_mallocz((channels * sizeof(AV_LQMixerChannelInfo)) + FF_INPUT_BUFFER_PADDING_SIZE)))) { av_log(lq_mixer_data->mixer_data.mixctx, AV_LOG_ERROR, "Cannot allocate mixer channel data.\n"); return old_channels; } lq_mixer_data->mixer_data.volume_boost = amplify; lq_mixer_data->mixer_data.volume_left = left_volume; lq_mixer_data->mixer_data.volume_right = right_volume; lq_mixer_data->mixer_data.channels_in = channels; if ((old_channels != channels) || (lq_mixer_data->amplify != amplify)) { - int32_t *volume_lut = lq_mixer_data->volume_lut; - uint32_t volume_mult = 0, volume_div = channels << 8; - uint8_t i = 0, j = 0; + int32_t *volume_lut = lq_mixer_data->volume_lut; + int32_t volume_mult = 0, volume_div = channels << 8; + uint8_t i = 0, j = 0; lq_mixer_data->amplify = amplify; do { do { const int32_t volume = (int8_t) j << 8; - *volume_lut++ = (int64_t) volume * volume_mult / volume_div; + *volume_lut++ = ((int64_t) volume * volume_mult) / volume_div; } while (++j); volume_mult += amplify; } while (++i); } if (channel_info && (old_channels != channels)) { uint32_t copy_channels = old_channels; uint16_t i; if (copy_channels > channels) copy_channels = channels; memcpy(channel_info, old_channel_info, copy_channels * sizeof(AV_LQMixerChannelInfo)); lq_mixer_data->channel_info = channel_info; lq_mixer_data->channels_in = channels; channel_info += copy_channels; for (i = copy_channels; i < channels; ++i) { set_sample_filter(lq_mixer_data, &channel_info->current, 127, 0); set_sample_filter(lq_mixer_data, &channel_info->next, 127, 0); channel_info++; } av_free(old_channel_info); } channel_info = lq_mixer_data->channel_info; for (i = channels; i > 0; i--) { set_sample_mix_rate(lq_mixer_data, &channel_info->current, channel_info->current.rate); channel_info++; } return channels; } static av_cold void get_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel->pos = channel_info->current.offset; mixer_channel->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel->flags = channel_info->current.flags; mixer_channel->volume = channel_info->current.volume; mixer_channel->panning = channel_info->current.panning; mixer_channel->data = channel_info->current.data; mixer_channel->len = channel_info->current.len; mixer_channel->repeat_start = channel_info->current.repeat; mixer_channel->repeat_length = channel_info->current.repeat_len; mixer_channel->repeat_count = channel_info->current.count_restart; mixer_channel->repeat_counted = channel_info->current.counted; mixer_channel->rate = channel_info->current.rate; mixer_channel->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel->filter_damping = channel_info->current.filter_damping; } static av_cold void set_channel(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block; uint32_t repeat, repeat_len; channel_info->next.data = NULL; if (mixer_channel->flags & AVSEQ_MIXER_CHANNEL_FLAG_SYNTH) channel_block = &channel_info->next; else channel_block = &channel_info->current; channel_block->offset = mixer_channel->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel->bits_per_sample; channel_block->flags = mixer_channel->flags; channel_block->volume = mixer_channel->volume; channel_block->panning = mixer_channel->panning; channel_block->data = mixer_channel->data; channel_block->len = mixer_channel->len; repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel->repeat_count; channel_block->counted = mixer_channel->repeat_counted; set_sample_filter(lq_mixer_data, channel_block, mixer_channel->filter_cutoff, mixer_channel->filter_damping); set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel->rate); } static av_cold void reset_channel(AVMixerData *mixer_data, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; set_sample_filter(lq_mixer_data, channel_block, 127, 0); channel_block = &channel_info->next; channel_block->offset = 0; channel_block->fraction = 0; channel_block->bits_per_sample = 0; channel_block->flags = 0; channel_block->volume = 0; channel_block->panning = 0; channel_block->data = NULL; channel_block->len = 0; repeat = 0; repeat_len = 0; channel_block->repeat = 0; channel_block->repeat_len = 0; channel_block->end_offset = 0; channel_block->restart_offset = 0; channel_block->count_restart = 0; channel_block->counted = 0; channel_block->filter_tmp1 = 0; channel_block->filter_tmp2 = 0; set_sample_filter(lq_mixer_data, channel_block, 127, 0); } static av_cold void get_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; const AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; mixer_channel_current->pos = channel_info->current.offset; mixer_channel_current->bits_per_sample = channel_info->current.bits_per_sample; mixer_channel_current->flags = channel_info->current.flags; mixer_channel_current->volume = channel_info->current.volume; mixer_channel_current->panning = channel_info->current.panning; mixer_channel_current->data = channel_info->current.data; mixer_channel_current->len = channel_info->current.len; mixer_channel_current->repeat_start = channel_info->current.repeat; mixer_channel_current->repeat_length = channel_info->current.repeat_len; mixer_channel_current->repeat_count = channel_info->current.count_restart; mixer_channel_current->repeat_counted = channel_info->current.counted; mixer_channel_current->rate = channel_info->current.rate; mixer_channel_current->filter_cutoff = channel_info->current.filter_cutoff; mixer_channel_current->filter_damping = channel_info->current.filter_damping; mixer_channel_next->pos = channel_info->next.offset; mixer_channel_next->bits_per_sample = channel_info->next.bits_per_sample; mixer_channel_next->flags = channel_info->next.flags; mixer_channel_next->volume = channel_info->next.volume; mixer_channel_next->panning = channel_info->next.panning; mixer_channel_next->data = channel_info->next.data; mixer_channel_next->len = channel_info->next.len; mixer_channel_next->repeat_start = channel_info->next.repeat; mixer_channel_next->repeat_length = channel_info->next.repeat_len; mixer_channel_next->repeat_count = channel_info->next.count_restart; mixer_channel_next->repeat_counted = channel_info->next.counted; mixer_channel_next->rate = channel_info->next.rate; mixer_channel_next->filter_cutoff = channel_info->next.filter_cutoff; mixer_channel_next->filter_damping = channel_info->next.filter_damping; } static av_cold void set_both_channels(AVMixerData *mixer_data, AVMixerChannel *mixer_channel_current, AVMixerChannel *mixer_channel_next, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; struct ChannelBlock *channel_block = &channel_info->current; uint32_t repeat, repeat_len; channel_block->offset = mixer_channel_current->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_current->bits_per_sample; channel_block->flags = mixer_channel_current->flags; channel_block->volume = mixer_channel_current->volume; channel_block->panning = mixer_channel_current->panning; channel_block->data = mixer_channel_current->data; channel_block->len = mixer_channel_current->len; repeat = mixer_channel_current->repeat_start; repeat_len = mixer_channel_current->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_current->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_current->repeat_count; channel_block->counted = mixer_channel_current->repeat_counted; set_sample_filter(lq_mixer_data, channel_block, mixer_channel_current->filter_cutoff, mixer_channel_current->filter_damping); set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel_current->rate); channel_block = &channel_info->next; channel_block->offset = mixer_channel_next->pos; channel_block->fraction = 0; channel_block->bits_per_sample = mixer_channel_next->bits_per_sample; channel_block->flags = mixer_channel_next->flags; channel_block->volume = mixer_channel_next->volume; channel_block->panning = mixer_channel_next->panning; channel_block->data = mixer_channel_next->data; channel_block->len = mixer_channel_next->len; repeat = mixer_channel_next->repeat_start; repeat_len = mixer_channel_next->repeat_length; channel_block->repeat = repeat; channel_block->repeat_len = repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel_next->len; repeat_len = 0; } repeat += repeat_len; if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_block->end_offset = repeat; channel_block->restart_offset = repeat_len; channel_block->count_restart = mixer_channel_next->repeat_count; channel_block->counted = mixer_channel_next->repeat_counted; set_sample_filter(lq_mixer_data, channel_block, mixer_channel_next->filter_cutoff, mixer_channel_next->filter_damping); set_sample_mix_rate(lq_mixer_data, channel_block, mixer_channel_next->rate); } static av_cold void set_channel_volume_panning_pitch(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if ((channel_info->current.volume == mixer_channel->volume) && (channel_info->current.panning == mixer_channel->panning)) { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; uint32_t rate_frac; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; } else { const uint32_t rate = mixer_channel->rate, mix_rate = lq_mixer_data->mix_rate; const uint8_t volume = mixer_channel->volume; const int8_t panning = mixer_channel->panning; uint32_t rate_frac; channel_info->current.volume = volume; channel_info->next.volume = volume; channel_info->current.panning = panning; channel_info->next.panning = panning; channel_info->current.rate = rate; channel_info->next.rate = rate; rate_frac = rate / mix_rate; channel_info->current.advance = rate_frac; channel_info->next.advance = rate_frac; rate_frac = (((uint64_t) rate % mix_rate) << 32) / mix_rate; channel_info->current.advance_frac = rate_frac; channel_info->next.advance_frac = rate_frac; set_mix_functions(lq_mixer_data, &channel_info->current); set_mix_functions(lq_mixer_data, &channel_info->next); } } static av_cold void set_channel_position_repeat_flags(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; if (channel_info->current.flags == mixer_channel->flags) { uint32_t repeat = mixer_channel->pos, repeat_len; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; } else { uint32_t repeat, repeat_len; channel_info->current.flags = mixer_channel->flags; repeat = mixer_channel->pos; if (repeat != channel_info->current.offset) { channel_info->current.offset = repeat; channel_info->current.fraction = 0; } repeat = mixer_channel->repeat_start; repeat_len = mixer_channel->repeat_length; channel_info->current.repeat = repeat; channel_info->current.repeat_len = repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) { repeat = mixer_channel->len; repeat_len = 0; } repeat += repeat_len; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { repeat -= repeat_len; if (!(channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) repeat = -1; } channel_info->current.end_offset = repeat; channel_info->current.restart_offset = repeat_len; channel_info->current.count_restart = mixer_channel->repeat_count; channel_info->current.counted = mixer_channel->repeat_counted; set_mix_functions(lq_mixer_data, &channel_info->current); } } static av_cold void set_channel_filter(AVMixerData *mixer_data, AVMixerChannel *mixer_channel, uint32_t channel) { const AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; AV_LQMixerChannelInfo *const channel_info = lq_mixer_data->channel_info + channel; set_sample_filter(lq_mixer_data, &channel_info->current, mixer_channel->filter_cutoff, mixer_channel->filter_damping); } static av_cold void mix(AVMixerData *mixer_data, int32_t *buf) { AV_LQMixerData *const lq_mixer_data = (AV_LQMixerData *) mixer_data; uint32_t mix_rate, current_left, current_left_frac, buf_size; if (!(lq_mixer_data->mixer_data.flags & AVSEQ_MIXER_DATA_FLAG_FROZEN)) { mix_rate = lq_mixer_data->mix_rate; current_left = lq_mixer_data->current_left; current_left_frac = lq_mixer_data->current_left_frac; buf_size = lq_mixer_data->buf_size; memset(buf, 0, buf_size << ((lq_mixer_data->channels_out >= 2) ? 3 : 2)); while (buf_size) { if (current_left) { uint32_t mix_len = buf_size; if (buf_size > current_left) mix_len = current_left; current_left -= mix_len; buf_size -= mix_len; mix_sample(lq_mixer_data, buf, mix_len); buf += (lq_mixer_data->channels_out >= 2) ? mix_len << 1 : mix_len; } if (current_left) continue; if (mixer_data->handler) mixer_data->handler(mixer_data); current_left = lq_mixer_data->pass_len; current_left_frac += lq_mixer_data->pass_len_frac; if (current_left_frac < lq_mixer_data->pass_len_frac) current_left++; } lq_mixer_data->current_left = current_left; lq_mixer_data->current_left_frac = current_left_frac; } // TODO: Execute post-processing step in libavfilter and pass the PCM data. } AVMixerContext low_quality_mixer = { .av_class = &avseq_low_quality_mixer_class, .name = "Low quality mixer", .description = NULL_IF_CONFIG_SMALL("Optimized for speed and supports linear interpolation."), .flags = AVSEQ_MIXER_CONTEXT_FLAG_SURROUND|AVSEQ_MIXER_CONTEXT_FLAG_AVFILTER, .frequency = 44100, .frequency_min = 1000, .frequency_max = 768000, .buf_size = 512, .buf_size_min = 64, .buf_size_max = 32768, .volume_boost = 0x10000, .channels_in = 65535, .channels_out = 2, .init = init, .uninit = uninit, .set_rate = set_rate, .set_tempo = set_tempo, .set_volume = set_volume, .get_channel = get_channel, .set_channel = set_channel, .reset_channel = reset_channel, .get_both_channels = get_both_channels, .set_both_channels = set_both_channels, .set_channel_volume_panning_pitch = set_channel_volume_panning_pitch, .set_channel_position_repeat_flags = set_channel_position_repeat_flags, .set_channel_filter = set_channel_filter, .mix = mix, }; #endif /* CONFIG_LOW_QUALITY_MIXER */
BastyCDGS/ffmpeg-soc
7e9697b181970d07f3ca93f48ea3e1d6704be5e0
Fixed backwards looping calculation in high quality mixer.
diff --git a/libavsequencer/hq_mixer.c b/libavsequencer/hq_mixer.c index c32a5fc..c5e8ada 100644 --- a/libavsequencer/hq_mixer.c +++ b/libavsequencer/hq_mixer.c @@ -1,1443 +1,1443 @@ /* * Sequencer high quality integer mixer * Copyright (c) 2010 Sebastian Vater <[email protected]> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Sequencer high quality integer mixer. */ #include "libavcodec/avcodec.h" #include "libavutil/avstring.h" #include "libavsequencer/mixer.h" typedef struct AV_HQMixerData { AVMixerData mixer_data; int32_t *buf; int32_t *filter_buf; uint32_t buf_size; uint32_t mix_buf_size; int32_t *volume_lut; struct AV_HQMixerChannelInfo *channel_info; uint32_t amplify; uint32_t mix_rate; uint32_t mix_rate_frac; uint32_t current_left; uint32_t current_left_frac; uint32_t pass_len; uint32_t pass_len_frac; uint16_t channels_in; uint16_t channels_out; uint8_t interpolation; uint8_t real_16_bit_mode; } AV_HQMixerData; typedef struct AV_HQMixerChannelInfo { struct ChannelBlock { const int16_t *data; uint32_t len; uint32_t offset; uint32_t fraction; uint32_t advance; uint32_t advance_frac; void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint32_t end_offset; uint32_t restart_offset; uint32_t repeat; uint32_t repeat_len; uint32_t count_restart; uint32_t counted; uint32_t rate; int32_t *volume_left_lut; int32_t *volume_right_lut; uint32_t mult_left_volume; uint32_t div_volume; uint32_t mult_right_volume; int32_t filter_c1; int32_t filter_c2; int32_t filter_c3; int32_t filter_tmp1; int32_t filter_tmp2; void (*mix_backwards_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); uint8_t bits_per_sample; uint8_t flags; uint8_t volume; uint8_t panning; uint8_t filter_cutoff; uint8_t filter_damping; } current; struct ChannelBlock next; int32_t prev_sample; int32_t curr_sample; int32_t next_sample; int32_t prev_sample_r; int32_t curr_sample_r; int32_t next_sample_r; int mix_right; } AV_HQMixerChannelInfo; #if CONFIG_HIGH_QUALITY_MIXER static const char *high_quality_mixer_name(void *p) { AVMixerContext *mixctx = p; return mixctx->name; } static const AVClass avseq_high_quality_mixer_class = { "AVSequencer High Quality Mixer", high_quality_mixer_name, NULL, LIBAVUTIL_VERSION_INT, }; static void apply_filter(struct ChannelBlock *const channel_block, int32_t **const dest_buf, const int32_t *src_buf, const uint32_t len) { int32_t *mix_buf = *dest_buf; uint32_t i = len >> 2; int32_t c1 = channel_block->filter_c1; int32_t c2 = channel_block->filter_c2; int32_t c3 = channel_block->filter_c3; int32_t o1 = channel_block->filter_tmp2; int32_t o2 = channel_block->filter_tmp1; int32_t o3, o4; while (i--) { mix_buf[0] += o3 = (((int64_t) c1 * src_buf[0]) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; mix_buf[1] += o4 = (((int64_t) c1 * src_buf[1]) + ((int64_t) c2 * o3) + ((int64_t) c3 * o2)) >> 24; mix_buf[2] += o1 = (((int64_t) c1 * src_buf[2]) + ((int64_t) c2 * o4) + ((int64_t) c3 * o3)) >> 24; mix_buf[3] += o2 = (((int64_t) c1 * src_buf[3]) + ((int64_t) c2 * o1) + ((int64_t) c3 * o4)) >> 24; src_buf += 4; mix_buf += 4; } i = len & 3; while (i--) { *mix_buf++ += o3 = (((int64_t) c1 * *src_buf++) + ((int64_t) c2 * o2) + ((int64_t) c3 * o1)) >> 24; o1 = o2; o2 = o3; } *dest_buf = mix_buf; channel_block->filter_tmp1 = o2; channel_block->filter_tmp2 = o1; } static void mix_sample(AV_HQMixerData *const mixer_data, int32_t *const buf, const uint32_t len) { AV_HQMixerChannelInfo *channel_info = mixer_data->channel_info; uint16_t i = mixer_data->channels_in; do { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PLAY) { void (*mix_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); int32_t *mix_buf = buf; uint32_t offset = channel_info->current.offset; uint32_t fraction = channel_info->current.fraction; const uint32_t advance = channel_info->current.advance; const uint32_t adv_frac = channel_info->current.advance_frac; uint32_t remain_len = len, remain_mix; uint32_t counted; uint32_t count_restart; uint64_t calc_mix; mix_func = channel_info->current.mix_func; if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS) { mix_sample_backwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = offset - channel_info->current.end_offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(&channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((int32_t) offset <= (int32_t) channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(&channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (((int32_t) offset > (int32_t) channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { counted = channel_info->current.counted++; if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = -1; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix += channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if ((int32_t) remain_len > 0) goto mix_sample_forwards; break; } else { offset += channel_info->current.restart_offset; if (channel_info->next.data) goto mix_sample_synth; if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) goto mix_sample_synth; else channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; break; } } } else { mix_sample_forwards: for (;;) { calc_mix = (((((uint64_t) advance << 32) + adv_frac) * remain_len) + fraction) >> 32; if ((int32_t) (remain_mix = channel_info->current.end_offset - offset) > 0) { if ((uint32_t) calc_mix < remain_mix) { if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, remain_len); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = remain_len; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, remain_len); apply_filter(&channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if (offset >= channel_info->current.end_offset) remain_len = 0; else break; } else { calc_mix = (((((uint64_t) remain_mix << 32) - fraction) - 1) / (((uint64_t) advance << 32) + adv_frac) + 1); remain_len -= (uint32_t) calc_mix; if ((channel_info->current.filter_cutoff == 127) && (channel_info->current.filter_damping == 0)) { mix_func(mixer_data, channel_info, &channel_info->current, &mix_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); } else { int32_t *filter_buf = mixer_data->filter_buf; uint32_t filter_len = (uint32_t) calc_mix; if (mixer_data->channels_out >= 2) filter_len <<= 1; memset(filter_buf, 0, filter_len * sizeof(int32_t)); mix_func(mixer_data, channel_info, &channel_info->current, &filter_buf, &offset, &fraction, advance, adv_frac, (uint32_t) calc_mix); apply_filter(&channel_info->current, &mix_buf, mixer_data->filter_buf, filter_len); } if ((offset < channel_info->current.end_offset) && !remain_len) break; } } if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { counted = channel_info->current.counted++; if ((count_restart = channel_info->current.count_restart) && (count_restart == counted)) { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_LOOP; channel_info->current.end_offset = channel_info->current.len; goto mix_sample_synth; } else { if (channel_info->current.flags & AVSEQ_MIXER_CHANNEL_FLAG_PINGPONG) { void (*mixer_change_func)(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len); if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } mixer_change_func = channel_info->current.mix_backwards_func; channel_info->current.mix_backwards_func = mix_func; mix_func = mixer_change_func; channel_info->current.mix_func = mix_func; channel_info->current.flags ^= AVSEQ_MIXER_CHANNEL_FLAG_BACKWARDS; remain_mix = channel_info->current.end_offset; offset -= remain_mix; offset = -offset + remain_mix; remain_mix -= channel_info->current.restart_offset; channel_info->current.end_offset = remain_mix; if (remain_len) goto mix_sample_backwards; break; } else { offset -= channel_info->current.restart_offset; if (channel_info->next.data) { memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; } if ((int32_t) remain_len > 0) continue; break; } } } else { if (channel_info->next.data) { mix_sample_synth: memcpy(&channel_info->current, &channel_info->next, sizeof(struct ChannelBlock)); channel_info->next.data = NULL; if ((int32_t) remain_len > 0) continue; } else { channel_info->current.flags &= ~AVSEQ_MIXER_CHANNEL_FLAG_PLAY; } break; } } } channel_info->current.offset = offset; channel_info->current.fraction = fraction; } channel_info++; } while (--i); } #define MIX(type) \ static void mix_##type(const AV_HQMixerData *const mixer_data, \ struct AV_HQMixerChannelInfo *const channel_info, \ const struct ChannelBlock *const channel_block, \ int32_t **const buf, uint32_t *const offset, uint32_t *const fraction, \ const uint32_t advance, const uint32_t adv_frac, const uint32_t len) MIX(skip) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset += skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset++; *offset = curr_offset; *fraction = curr_frac; } MIX(skip_backwards) { uint32_t curr_offset = *offset, curr_frac = *fraction, skip_div; const uint64_t skip_len = (((uint64_t) advance << 32) + adv_frac) * len; skip_div = skip_len >> 32; curr_offset -= skip_div; skip_div = skip_len; curr_frac += skip_div; if (curr_frac < skip_div) curr_offset--; *offset = curr_offset; *fraction = curr_frac; } static void get_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int8_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset + 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int8_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint8_t) sample[offset - 1]]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint16_t) sample[offset + 1] >> 8]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint16_t) sample[offset - 1] >> 8]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint32_t) sample[offset + 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; int32_t smp; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = volume_lut[(uint32_t) sample[offset - 1] >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x_to_8(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = volume_lut[(uint32_t) smp_data >> 24]; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_16(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int16_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset + 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_32(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; int32_t smp; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } smp = ((int64_t) sample[offset - 1] * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (offset >= (channel_block->end_offset - 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset -= channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = ++offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static void get_backwards_next_sample_x(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; int32_t smp; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; - if (offset < (channel_block->end_offset + 1)) { + if ((int32_t) offset <= ((int32_t) channel_block->end_offset + 1)) { if (channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP) { struct ChannelBlock *channel_next_block = &channel_info->next; offset += channel_block->restart_offset; if (channel_next_block->data) { sample = (const int32_t *) channel_next_block->data; offset += channel_next_block->offset; } } else { if (channel_info->mix_right) channel_info->next_sample_r = 0; else channel_info->next_sample = 0; return; } } bit = --offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } smp = ((int64_t) smp_data * mult_volume) / div_volume; if (channel_info->mix_right) channel_info->next_sample_r = smp; else channel_info->next_sample = smp; } static int32_t get_curr_sample_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_curr_sample_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_curr_sample_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_curr_sample_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *const volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_curr_sample_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_curr_sample_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_backwards_sample_1_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int8_t *sample = (const int8_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint8_t) sample[offset]]; } static int32_t get_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_backwards_sample_1_16_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint16_t) sample[offset] >> 8]; } static int32_t get_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_backwards_sample_1_32_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return volume_lut[(uint32_t) sample[offset] >> 24]; } static int32_t get_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_backwards_sample_1_x_to_8(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int32_t *sample = (const int32_t *) channel_block->data; const int32_t *volume_lut = channel_info->mix_right ? channel_block->volume_right_lut : channel_block->volume_left_lut; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return volume_lut[(uint32_t) smp_data >> 24]; } static int32_t get_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_16(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_32(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } return ((int64_t) sample[offset] * mult_volume) / div_volume; } static int32_t get_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset >= end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset -= restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[offset] << bit; smp_data |= ((uint32_t) sample[offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static int32_t get_backwards_sample_1_x(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const interpolate_frac) { const int16_t *sample = (const int16_t *) channel_block->data; const int32_t mult_volume = channel_info->mix_right ? channel_block->mult_right_volume : channel_block->mult_left_volume; const int32_t div_volume = channel_block->div_volume; const uint32_t bits_per_sample = channel_block->bits_per_sample; uint32_t end_offset = channel_block->end_offset; uint32_t restart_offset = channel_block->restart_offset; uint32_t bit; uint32_t smp_offset; uint32_t smp_data; if (interpolate_frac) *interpolate_frac += 0x1000000; while (offset < end_offset) { if (!(channel_block->flags & AVSEQ_MIXER_CHANNEL_FLAG_LOOP)) return 0; offset += restart_offset; } bit = offset * bits_per_sample; smp_offset = bit >> 5; if (((bit &= 31) + bits_per_sample) < 32) { smp_data = ((uint32_t) sample[smp_offset] << bit) & ~((1 << (32 - bits_per_sample)) - 1); } else { smp_data = (uint32_t) sample[smp_offset] << bit; smp_data |= ((uint32_t) sample[smp_offset+1] & ~((1 << (64 - (bit + bits_per_sample))) - 1)) >> (32 - bit); } return ((int64_t) smp_data * mult_volume) / div_volume; } static void mix_mono_loop(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, void (*get_next_sample_func)(struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf; uint32_t curr_offset = *offset; uint32_t curr_frac = *fraction; uint32_t i = len; int32_t smp; get_next_sample_func(channel_info, channel_block, curr_offset); do { int32_t interpolate_frac = -(channel_info->prev_sample - channel_info->curr_sample); int32_t interpolate_div = (channel_info->next_sample - (channel_info->curr_sample + interpolate_frac)) >> 2; int32_t smp_value; smp = (uint32_t) curr_frac >> 1; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div = ((interpolate_div << 2) + interpolate_frac) >> 2; interpolate_div = ((int64_t) smp * interpolate_div) >> 32; interpolate_div <<= 3; smp_value = (channel_info->prev_sample + channel_info->curr_sample) >> 1; smp = smp_value + interpolate_div; if (((smp_value ^ smp) & (interpolate_div ^ smp)) < 0) smp = channel_info->curr_sample; *mix_buf++ += smp; curr_frac += adv_frac; if (curr_frac < adv_frac) { curr_offset += offset_inc; channel_info->prev_sample = channel_info->curr_sample; channel_info->curr_sample = channel_info->next_sample; get_next_sample_func(channel_info, channel_block, curr_offset); } } while (--i); *buf = mix_buf; *offset = curr_offset; *fraction = curr_frac; } static void mix_average_mono(const AV_HQMixerData *const mixer_data, struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, int32_t **const buf, int32_t (*get_curr_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, const uint32_t offset), int32_t (*get_sample_func)(const struct AV_HQMixerChannelInfo *const channel_info, const struct ChannelBlock *const channel_block, uint32_t offset, uint32_t *const adv_frac), const uint32_t offset_inc, uint32_t *const offset, uint32_t *const fraction, const uint32_t advance, const uint32_t adv_frac, const uint32_t len) { int32_t *mix_buf = *buf;
BastyCDGS/ffmpeg-soc
83b5b61c6f4c88039a06ceecaea4a13eafb81c66
Forgot to remove old overflow status flag handling code in synth sound assembler's SUBX instruction.
diff --git a/libavsequencer/player.c b/libavsequencer/player.c index 463cbff..c69e912 100644 --- a/libavsequencer/player.c +++ b/libavsequencer/player.c @@ -5116,1027 +5116,1024 @@ static void se_vibrato_do(const AVSequencerContext *const avctx, AVSequencerPlay player_channel->vibrato_slide -= old_frequency - player_channel->frequency; } static void se_arpegio_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, const int16_t arpeggio_transpose, uint16_t arpeggio_finetune) { const uint32_t *frequency_lut; uint32_t frequency, next_frequency, slide_frequency, old_frequency; uint16_t octave; int16_t note; octave = arpeggio_transpose / 12; note = arpeggio_transpose % 12; if (note < 0) { octave--; note += 12; arpeggio_finetune = -arpeggio_finetune; } frequency_lut = (avctx->frequency_lut ? avctx->frequency_lut : pitch_lut) + note + 1; frequency = *frequency_lut++; next_frequency = *frequency_lut - frequency; frequency += (int32_t) (arpeggio_finetune * (int16_t) next_frequency) >> 8; if ((int16_t) (octave) < 0) { octave = -octave; frequency >>= octave; } else { frequency <<= octave; } old_frequency = player_channel->frequency; slide_frequency = player_channel->arpeggio_slide + old_frequency; player_channel->frequency = frequency = ((uint64_t) frequency * slide_frequency) >> 16; player_channel->arpeggio_slide += old_frequency - frequency; } static void se_tremolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t tremolo_slide_value) { uint16_t volume = player_channel->volume; tremolo_slide_value -= player_channel->tremolo_slide; if ((tremolo_slide_value += volume) < 0) tremolo_slide_value = 0; if (tremolo_slide_value > 255) tremolo_slide_value = 255; player_channel->volume = tremolo_slide_value; player_channel->tremolo_slide -= volume - tremolo_slide_value; } static void se_pannolo_do(const AVSequencerContext *const avctx, AVSequencerPlayerChannel *const player_channel, int32_t pannolo_slide_value) { uint16_t panning = (uint8_t) player_channel->panning; pannolo_slide_value -= player_channel->pannolo_slide; if ((pannolo_slide_value += panning) < 0) pannolo_slide_value = 0; if (pannolo_slide_value > 255) pannolo_slide_value = 255; player_channel->panning = pannolo_slide_value; player_channel->pannolo_slide -= panning - pannolo_slide_value; } #define EXECUTE_SYNTH_CODE_INSTRUCTION(fx_type) \ static uint16_t se_##fx_type(AVSequencerContext *const avctx, \ AVSequencerPlayerChannel *const player_channel, \ const uint16_t virtual_channel, \ uint16_t synth_code_line, \ const int src_var, \ int dst_var, \ uint16_t instruction_data, \ const int synth_type) EXECUTE_SYNTH_CODE_INSTRUCTION(stop) { instruction_data += player_channel->variable[src_var]; if (instruction_data & 0x8000) player_channel->stop_forbid_mask &= ~instruction_data; else player_channel->stop_forbid_mask |= instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(kill) { instruction_data += player_channel->variable[src_var]; player_channel->kill_count[synth_type] = instruction_data; player_channel->synth_flags |= 1 << synth_type; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(wait) { instruction_data += player_channel->variable[src_var]; player_channel->wait_count[synth_type] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitvol) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~0; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitpan) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~1; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitsld) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~2; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(waitspc) { instruction_data += player_channel->variable[src_var]; player_channel->wait_line[synth_type] = instruction_data; player_channel->wait_type[synth_type] = ~3; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jump) { instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpeq) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpne) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppl) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpmi) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumplt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumple) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if ((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpgt) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!(synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO)) { synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpge) { uint16_t synth_cond_var = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE); if (!((synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) || (synth_cond_var == AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcs) { if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpcc) { if (!(player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpls) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if ((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY)) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumphi) { uint16_t synth_cond_var = player_channel->cond_var[synth_type]; if (!((synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO) && (synth_cond_var & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY))) { instruction_data += player_channel->variable[src_var]; return instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpvol) { if (!(player_channel->stop_forbid_mask & 1)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[0] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumppan) { if (!(player_channel->stop_forbid_mask & 2)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[1] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpsld) { if (!(player_channel->stop_forbid_mask & 4)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[2] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(jumpspc) { if (!(player_channel->stop_forbid_mask & 8)) { instruction_data += player_channel->variable[src_var]; player_channel->entry_pos[3] = instruction_data; } return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(call) { player_channel->variable[dst_var] = synth_code_line; instruction_data += player_channel->variable[src_var]; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(ret) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = --synth_code_line; return instruction_data; } EXECUTE_SYNTH_CODE_INSTRUCTION(posvar) { player_channel->variable[src_var] += synth_code_line + --instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(load) { instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = instruction_data; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(add) { uint16_t flags = 0; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int16_t) player_channel->variable[dst_var] + (int16_t) instruction_data; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; player_channel->variable[dst_var] = add_data; if (player_channel->variable[dst_var] < instruction_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (!add_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(addx) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; uint32_t add_unsigned_data; int32_t add_data; instruction_data += player_channel->variable[src_var]; add_data = (int16_t) player_channel->variable[dst_var] + (int16_t) instruction_data; add_unsigned_data = instruction_data; if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND) { add_data++; add_unsigned_data++; if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) ++instruction_data ^ add_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } else if ((((int16_t) player_channel->variable[dst_var] ^ add_data) & ((int16_t) instruction_data ^ add_data)) < 0) { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } player_channel->variable[dst_var] = add_data; if ((player_channel->variable[dst_var] < add_unsigned_data)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if (add_data) flags &= ~AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (add_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(sub) { uint16_t flags = 0; int32_t sub_data; instruction_data += player_channel->variable[src_var]; sub_data = (int16_t) player_channel->variable[dst_var] - (int16_t) instruction_data; if (player_channel->variable[dst_var] < instruction_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if ((((int16_t) player_channel->variable[dst_var] ^ sub_data) & (((int16_t) -instruction_data) ^ sub_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; player_channel->variable[dst_var] = sub_data; if (!sub_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (sub_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(subx) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; uint32_t sub_unsigned_data; int32_t sub_data; instruction_data += player_channel->variable[src_var]; sub_data = (int16_t) player_channel->variable[dst_var] - (int16_t) instruction_data; sub_unsigned_data = instruction_data; if (player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND) { sub_data--; sub_unsigned_data++; if ((((int16_t) player_channel->variable[dst_var] ^ sub_data) & ((int16_t) -(++instruction_data) ^ sub_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } else if ((((int16_t) player_channel->variable[dst_var] ^ sub_data) & (((int16_t) -instruction_data) ^ sub_data)) < 0) { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } if (player_channel->variable[dst_var] < sub_unsigned_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; player_channel->variable[dst_var] = sub_data; - if ((sub_data < -0x8000) || (sub_data >= 0x8000)) - flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; - if (sub_data) flags &= ~AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (sub_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(cmp) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; int32_t sub_data; instruction_data += player_channel->variable[src_var]; sub_data = (int16_t) player_channel->variable[dst_var] - (int16_t) instruction_data; if ((((int16_t) player_channel->variable[dst_var] ^ sub_data) & (((int16_t) -instruction_data) ^ sub_data)) < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; if (player_channel->variable[dst_var] < instruction_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY; if (!sub_data) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (sub_data < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(mulu) { uint32_t umult_res, flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = umult_res = (uint32_t) player_channel->variable[dst_var] * (uint16_t) instruction_data; if (!umult_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (umult_res >= 0x10000) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; if ((int16_t) umult_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(muls) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; int32_t smult_res; instruction_data += player_channel->variable[src_var]; player_channel->variable[dst_var] = smult_res = (int32_t) player_channel->variable[dst_var] * (int16_t) instruction_data; if (!smult_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((smult_res < -0x8000) || (smult_res > 0x7FFF)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; if ((int16_t) smult_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(dmulu) { uint32_t umult_res; uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; instruction_data |= player_channel->variable[src_var]; umult_res = player_channel->variable[dst_var] * instruction_data; if (dst_var == 15) { player_channel->variable[dst_var] = umult_res; if (umult_res >= 0x10000) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; umult_res <<= 16; } else { player_channel->variable[dst_var++] = umult_res >> 16; player_channel->variable[dst_var] = umult_res; } if (!umult_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int32_t) umult_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(dmuls) { int32_t smult_res; uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; instruction_data += player_channel->variable[src_var]; smult_res = (int32_t) player_channel->variable[dst_var] * (int16_t) instruction_data; if (dst_var == 15) { player_channel->variable[dst_var] = smult_res; if ((smult_res < -0x8000) || (smult_res > 0x7FFF)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; smult_res <<= 16; } else { player_channel->variable[dst_var++] = smult_res >> 16; player_channel->variable[dst_var] = smult_res; } if (!smult_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (smult_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(divu) { uint16_t udiv_res, flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if ((instruction_data += player_channel->variable[src_var])) { player_channel->variable[dst_var] = udiv_res = player_channel->variable[dst_var] / instruction_data; if (!udiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int16_t) udiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(divs) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; int16_t sdiv_res; if ((instruction_data += player_channel->variable[src_var])) { player_channel->variable[dst_var] = sdiv_res = (int16_t) player_channel->variable[dst_var] / (int16_t) instruction_data; if (!sdiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (sdiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(modu) { uint16_t umod_res, flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if ((instruction_data += player_channel->variable[src_var])) { player_channel->variable[dst_var] = umod_res = player_channel->variable[dst_var] % instruction_data; if (!umod_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int16_t) umod_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(mods) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; int16_t smod_res; if ((instruction_data += player_channel->variable[src_var])) { player_channel->variable[dst_var] = smod_res = (int16_t) player_channel->variable[dst_var] % (int16_t) instruction_data; if (!smod_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if (smod_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(ddivu) { uint32_t udiv_res; uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if ((instruction_data += player_channel->variable[src_var])) { if (dst_var == 15) { player_channel->variable[dst_var] = udiv_res = ((uint32_t) player_channel->variable[dst_var] << 16) / instruction_data; if (udiv_res < 0x10000) { if (!udiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int32_t) udiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } } else { uint32_t dividend = ((uint32_t) player_channel->variable[dst_var + 1] << 16) + player_channel->variable[dst_var]; if ((udiv_res = (dividend / instruction_data)) < 0x10000) { player_channel->variable[dst_var--] = udiv_res; player_channel->variable[dst_var] = dividend % instruction_data; if (!udiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int32_t) udiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } } } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(ddivs) { int32_t sdiv_res; uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; if ((instruction_data += player_channel->variable[src_var])) { if (dst_var == 15) { player_channel->variable[dst_var] = sdiv_res = ((int32_t) player_channel->variable[dst_var] << 16) / (int16_t) instruction_data; if ((sdiv_res >= -0x8000) && (sdiv_res <= 0x7FFF)) { if (!sdiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int32_t) sdiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } } else { int32_t dividend = ((int32_t) player_channel->variable[dst_var + 1] << 16) + (int16_t) player_channel->variable[dst_var]; sdiv_res = dividend / instruction_data; if ((sdiv_res >= -0x8000) && (sdiv_res <= 0x7FFF)) { player_channel->variable[dst_var--] = sdiv_res; player_channel->variable[dst_var] = dividend % instruction_data; if (!sdiv_res) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; if ((int32_t) sdiv_res < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } } } else { flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW|AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO|AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; } player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(ashl) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND, high_bit; int16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; high_bit = shift_value & 0x8000; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND); if (shift_value & 0x8000) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; shift_value <<= 1; if (high_bit != (shift_value & 0x8000)) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_OVERFLOW; } if (shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(ashr) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; int16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND); if (shift_value & 1) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; shift_value >>= 1; } if (shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(lshl) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; uint16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND); if (shift_value & 0x8000) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; shift_value <<= 1; } if ((int16_t) shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(lshr) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; uint16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND); if (shift_value & 1) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; shift_value >>= 1; } if ((int16_t) shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(rol) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; uint16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY); if (shift_value & 0x8000) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY; shift_value <<= 1; if (flags & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY) shift_value++; } if ((int16_t) shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(ror) { uint16_t flags = player_channel->cond_var[synth_type] & AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND; uint16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY); if (shift_value & 1) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY; shift_value >>= 1; if (flags & AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY) shift_value += 0x8000; } if ((int16_t) shift_value < 0) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_NEGATIVE; if (!shift_value) flags |= AVSEQ_PLAYER_CHANNEL_COND_VAR_ZERO; player_channel->variable[dst_var] = shift_value; player_channel->cond_var[synth_type] = flags; return synth_code_line; } EXECUTE_SYNTH_CODE_INSTRUCTION(rolx) { uint16_t flags = player_channel->cond_var[synth_type] & (AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY|AVSEQ_PLAYER_CHANNEL_COND_VAR_EXTEND); uint16_t shift_value = player_channel->variable[dst_var]; instruction_data += player_channel->variable[src_var]; instruction_data &= 0x3F; while (instruction_data--) { flags &= ~(AVSEQ_PLAYER_CHANNEL_COND_VAR_CARRY);
sillygwailo/Kwaltz
010762a0cfdec1dfa5219613912eea207ca0fb37
Updating Drupal to 6.20
diff --git a/kwaltz/kwaltz.make b/kwaltz/kwaltz.make index 750ea9e..91aaff1 100644 --- a/kwaltz/kwaltz.make +++ b/kwaltz/kwaltz.make @@ -1,58 +1,58 @@ core = 6.x projects[drupal][type] = core projects[drupal][download][type] = cvs -projects[drupal][download][revision] = DRUPAL-6-19 +projects[drupal][download][revision] = DRUPAL-6-20 projects[drupal][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[drupal][download][module] = drupal projects[smart_menus][type] = "module" projects[smart_menus][download][type] = "cvs" projects[smart_menus][download][module] = "contributions/modules/smart_menus" projects[smart_menus][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[smart_menus][download][revision] = "DRUPAL-6--1-7" projects[module_grants][type] = "module" projects[module_grants][download][type] = "cvs" projects[module_grants][download][module] = "contributions/modules/module_grants" projects[module_grants][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[module_grants][download][revision] = "DRUPAL-6--3-6" projects[revisioning][type] = "module" projects[revisioning][download][type] = "cvs" projects[revisioning][download][module] = "contributions/modules/revisioning" projects[revisioning][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[revisioning][download][revision] = "DRUPAL-6--3-11" projects[token][type] = module projects[token][download][type] = "cvs" projects[token][download][module] = "contributions/modules/token" projects[token][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[token][download][revision] = "DRUPAL-6--1-15" projects[workflow][type] = module projects[workflow][download][type] = "cvs" projects[workflow][download][module] = "contributions/modules/workflow" projects[workflow][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[workflow][download][revision] = "DRUPAL-6--1-4" projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_5.patch" projects[diff][type] = "module" projects[diff][download][type] = "cvs" projects[diff][download][module] = "contributions/modules/diff" projects[diff][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[diff][download][revision] = "DRUPAL-6--2-1" projects[features][type] = "module" projects[features][download][type] = "cvs" projects[features][download][module] = "contributions/modules/features" projects[features][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[features][download][revision] = "DRUPAL-6--1-0" projects[install_profile_api][type] = "module" projects[install_profile_api][download][type] = "git" projects[install_profile_api][download][url] = "git://github.com/sillygwailo/install_profile_api.git" projects[kwaltz_workflow][type] = "module" projects[kwaltz_workflow][download][type] = "git" projects[kwaltz_workflow][download][url] = "git://github.com/sillygwailo/Kwaltz-Workflow.git" \ No newline at end of file
sillygwailo/Kwaltz
56e1ff6a20ffafffcba540f2d6954906e4553779
Updating Drupal to 6.19, Module Grants to 3.6, Revisioning to 3.11, Token to 1.15, Diff to 2.1, and Features to 1.0.
diff --git a/kwaltz/kwaltz.make b/kwaltz/kwaltz.make index 18a0098..750ea9e 100644 --- a/kwaltz/kwaltz.make +++ b/kwaltz/kwaltz.make @@ -1,58 +1,58 @@ core = 6.x projects[drupal][type] = core projects[drupal][download][type] = cvs -projects[drupal][download][revision] = DRUPAL-6-16 +projects[drupal][download][revision] = DRUPAL-6-19 projects[drupal][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[drupal][download][module] = drupal projects[smart_menus][type] = "module" projects[smart_menus][download][type] = "cvs" projects[smart_menus][download][module] = "contributions/modules/smart_menus" projects[smart_menus][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[smart_menus][download][revision] = "DRUPAL-6--1-5" +projects[smart_menus][download][revision] = "DRUPAL-6--1-7" projects[module_grants][type] = "module" projects[module_grants][download][type] = "cvs" projects[module_grants][download][module] = "contributions/modules/module_grants" projects[module_grants][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[module_grants][download][revision] = "DRUPAL-6--3-5" +projects[module_grants][download][revision] = "DRUPAL-6--3-6" projects[revisioning][type] = "module" projects[revisioning][download][type] = "cvs" projects[revisioning][download][module] = "contributions/modules/revisioning" projects[revisioning][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[revisioning][download][revision] = "DRUPAL-6--3-10" +projects[revisioning][download][revision] = "DRUPAL-6--3-11" projects[token][type] = module projects[token][download][type] = "cvs" projects[token][download][module] = "contributions/modules/token" projects[token][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[token][download][revision] = "DRUPAL-6--1-13" +projects[token][download][revision] = "DRUPAL-6--1-15" projects[workflow][type] = module projects[workflow][download][type] = "cvs" projects[workflow][download][module] = "contributions/modules/workflow" projects[workflow][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[workflow][download][revision] = "DRUPAL-6--1-4" projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_5.patch" projects[diff][type] = "module" projects[diff][download][type] = "cvs" projects[diff][download][module] = "contributions/modules/diff" projects[diff][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[diff][download][revision] = "DRUPAL-6--2-0" +projects[diff][download][revision] = "DRUPAL-6--2-1" projects[features][type] = "module" projects[features][download][type] = "cvs" projects[features][download][module] = "contributions/modules/features" projects[features][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[features][download][revision] = "DRUPAL-6--1-0-BETA8" +projects[features][download][revision] = "DRUPAL-6--1-0" projects[install_profile_api][type] = "module" projects[install_profile_api][download][type] = "git" projects[install_profile_api][download][url] = "git://github.com/sillygwailo/install_profile_api.git" projects[kwaltz_workflow][type] = "module" projects[kwaltz_workflow][download][type] = "git" projects[kwaltz_workflow][download][url] = "git://github.com/sillygwailo/Kwaltz-Workflow.git" \ No newline at end of file
sillygwailo/Kwaltz
03fa3c68a68a2506f7d0680d684ff5ae61867ac1
Updating the patch to include the latest patch to Workflow. Install the Kwaltz Workflow module from the Git repository.
diff --git a/kwaltz/kwaltz.make b/kwaltz/kwaltz.make index 9c87fc7..18a0098 100644 --- a/kwaltz/kwaltz.make +++ b/kwaltz/kwaltz.make @@ -1,54 +1,58 @@ core = 6.x projects[drupal][type] = core projects[drupal][download][type] = cvs projects[drupal][download][revision] = DRUPAL-6-16 projects[drupal][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[drupal][download][module] = drupal projects[smart_menus][type] = "module" projects[smart_menus][download][type] = "cvs" projects[smart_menus][download][module] = "contributions/modules/smart_menus" projects[smart_menus][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[smart_menus][download][revision] = "DRUPAL-6--1-5" projects[module_grants][type] = "module" projects[module_grants][download][type] = "cvs" projects[module_grants][download][module] = "contributions/modules/module_grants" projects[module_grants][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[module_grants][download][revision] = "DRUPAL-6--3-5" projects[revisioning][type] = "module" projects[revisioning][download][type] = "cvs" projects[revisioning][download][module] = "contributions/modules/revisioning" projects[revisioning][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[revisioning][download][revision] = "DRUPAL-6--3-10" projects[token][type] = module projects[token][download][type] = "cvs" projects[token][download][module] = "contributions/modules/token" projects[token][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[token][download][revision] = "DRUPAL-6--1-13" projects[workflow][type] = module projects[workflow][download][type] = "cvs" projects[workflow][download][module] = "contributions/modules/workflow" projects[workflow][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[workflow][download][revision] = "DRUPAL-6--1-4" -projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_1.patch" +projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_5.patch" projects[diff][type] = "module" projects[diff][download][type] = "cvs" projects[diff][download][module] = "contributions/modules/diff" projects[diff][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[diff][download][revision] = "DRUPAL-6--2-0" projects[features][type] = "module" projects[features][download][type] = "cvs" projects[features][download][module] = "contributions/modules/features" projects[features][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[features][download][revision] = "DRUPAL-6--1-0-BETA8" projects[install_profile_api][type] = "module" projects[install_profile_api][download][type] = "git" projects[install_profile_api][download][url] = "git://github.com/sillygwailo/install_profile_api.git" + +projects[kwaltz_workflow][type] = "module" +projects[kwaltz_workflow][download][type] = "git" +projects[kwaltz_workflow][download][url] = "git://github.com/sillygwailo/Kwaltz-Workflow.git" \ No newline at end of file
sillygwailo/Kwaltz
bfbc0c54b2b39084947ce1846ae566fbcdaa51ce
Remove access control code now that it's in the features module. Closes #3.
diff --git a/kwaltz/kwaltz.profile b/kwaltz/kwaltz.profile index fb0eae2..aa9e4a0 100644 --- a/kwaltz/kwaltz.profile +++ b/kwaltz/kwaltz.profile @@ -1,249 +1,207 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); $author_rid = install_add_role('Writer'); $moderator_rid = install_add_role('Moderator'); $publisher_rid = install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); - // Workflow requires a permissions rebuild. Otherwise Drupal - // complains, and manual intervention is necessary. - if (node_access_needs_rebuild()) { - node_access_rebuild(); - } - // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); // store some state IDs. We'll use them latter too. $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $original_state = $is_moderated; $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } - // build Workflow access control - - $access = array(); - - $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); - $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); - $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); - $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); - - $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); - - $rids = array_keys(user_roles(FALSE)); - - // default permissions are unchecked - $zeroes = array(); - foreach ($rids as $rid) { - $zeroes[$rid] = 0; - } - - // Anonymous and authenticated user roles get the view access permissions - // though as the instructions explain, they get overriden by the - // User management > Permissions page - $default_view_access = $zeroes; - $default_view_access[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID; - $default_view_access[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID; - - foreach ($moderation_workflow_states as $moderation_workflow_state) { - $access[$moderation_workflow_state] = array( - 'view' => $default_view_access, - 'update' => $zeroes, - 'delete' => $zeroes, - ); + // Workflow requires a permissions rebuild. Otherwise Drupal + // complains, and manual intervention is necessary. + if (node_access_needs_rebuild()) { + node_access_rebuild(); } - // modify the default access control permissions - $access[$draft]['update'][$author_rid] = $author_rid; - $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; - $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; - - // save the permissions - workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); - // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
dae232863e9a4b1d2f859ea69a9c8353a1c27e59
Match up the permissions to the instructions better.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index cfa491d..fb0eae2 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,242 +1,249 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); $author_rid = install_add_role('Writer'); $moderator_rid = install_add_role('Moderator'); $publisher_rid = install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); // store some state IDs. We'll use them latter too. $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $original_state = $is_moderated; $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } // build Workflow access control $access = array(); $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); $rids = array_keys(user_roles(FALSE)); // default permissions are unchecked - $zeros = array(); + $zeroes = array(); foreach ($rids as $rid) { $zeroes[$rid] = 0; } + + // Anonymous and authenticated user roles get the view access permissions + // though as the instructions explain, they get overriden by the + // User management > Permissions page + $default_view_access = $zeroes; + $default_view_access[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID; + $default_view_access[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID; foreach ($moderation_workflow_states as $moderation_workflow_state) { $access[$moderation_workflow_state] = array( - 'view' => $zeroes, + 'view' => $default_view_access, 'update' => $zeroes, 'delete' => $zeroes, ); } - // override default access control permissions - $access[$draft]['view'][$publisher_rid] = $publisher_rid; + // modify the default access control permissions + $access[$draft]['update'][$author_rid] = $author_rid; $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; // save the permissions workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
b503c19e49e9b1c5486fa12d052756344d9370c3
Remove duplicate code.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index c66f6c5..cfa491d 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,246 +1,242 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); $author_rid = install_add_role('Writer'); $moderator_rid = install_add_role('Moderator'); $publisher_rid = install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); - install_add_permissions($author_rid, $author_permissions); - install_add_permissions($moderator_rid, $moderator_permissions); - install_add_permissions($publisher_rid, $publisher_permissions); - // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); // store some state IDs. We'll use them latter too. $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $original_state = $is_moderated; $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } // build Workflow access control $access = array(); $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); $rids = array_keys(user_roles(FALSE)); // default permissions are unchecked $zeros = array(); foreach ($rids as $rid) { $zeroes[$rid] = 0; } foreach ($moderation_workflow_states as $moderation_workflow_state) { $access[$moderation_workflow_state] = array( 'view' => $zeroes, 'update' => $zeroes, 'delete' => $zeroes, ); } // override default access control permissions $access[$draft]['view'][$publisher_rid] = $publisher_rid; $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; // save the permissions workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
528284d68735eb70e862e6dc4ff4c9b1a9327fb9
Whitespace.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 4f468f2..c66f6c5 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,246 +1,246 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); $author_rid = install_add_role('Writer'); $moderator_rid = install_add_role('Moderator'); $publisher_rid = install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); install_add_permissions($author_rid, $author_permissions); install_add_permissions($moderator_rid, $moderator_permissions); install_add_permissions($publisher_rid, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( - 'workflow' => $moderation_workflow, - 'placement' => array( + 'workflow' => $moderation_workflow, + 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); // store some state IDs. We'll use them latter too. $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $original_state = $is_moderated; $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } // build Workflow access control $access = array(); $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); $rids = array_keys(user_roles(FALSE)); // default permissions are unchecked $zeros = array(); foreach ($rids as $rid) { $zeroes[$rid] = 0; } foreach ($moderation_workflow_states as $moderation_workflow_state) { $access[$moderation_workflow_state] = array( 'view' => $zeroes, 'update' => $zeroes, 'delete' => $zeroes, ); } // override default access control permissions $access[$draft]['view'][$publisher_rid] = $publisher_rid; $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; // save the permissions workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
3666a64d07499a24ebda8004a431d644677203cb
Reverting back to hard-coded Role IDs, but moving up the storage of their numeric values up.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index bd937a8..4f468f2 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,246 +1,246 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); - install_add_role('Writer'); - install_add_role('Moderator'); - install_add_role('Publisher'); + + $author_rid = install_add_role('Writer'); + $moderator_rid = install_add_role('Moderator'); + $publisher_rid = install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module - - $author_rid = install_get_rid('Writer'); - $moderator_rid = install_get_rid('Moderator'); - $publisher_rid = install_get_rid('Publisher'); + install_add_permissions(3, $author_permissions); + install_add_permissions(4, $moderator_permissions); + install_add_permissions(5, $publisher_permissions); install_add_permissions($author_rid, $author_permissions); install_add_permissions($moderator_rid, $moderator_permissions); install_add_permissions($publisher_rid, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); // store some state IDs. We'll use them latter too. $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $original_state = $is_moderated; $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } // build Workflow access control $access = array(); $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); $rids = array_keys(user_roles(FALSE)); // default permissions are unchecked $zeros = array(); foreach ($rids as $rid) { $zeroes[$rid] = 0; } foreach ($moderation_workflow_states as $moderation_workflow_state) { $access[$moderation_workflow_state] = array( 'view' => $zeroes, 'update' => $zeroes, 'delete' => $zeroes, ); } // override default access control permissions $access[$draft]['view'][$publisher_rid] = $publisher_rid; $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; // save the permissions workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
c8cb6bbd8ca874120138c7e244ed16486ad599bb
Working code to save workflow permissions.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index ed2e65d..bd937a8 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,204 +1,246 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module $author_rid = install_get_rid('Writer'); $moderator_rid = install_get_rid('Moderator'); $publisher_rid = install_get_rid('Publisher'); install_add_permissions($author_rid, $author_permissions); install_add_permissions($moderator_rid, $moderator_permissions); install_add_permissions($publisher_rid, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); - $original_state = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); - $transition_state = install_workflow_get_sid('Live', 'kwaltz_workflow'); + // store some state IDs. We'll use them latter too. + $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); + $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); + $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); + $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); + + $original_state = $is_moderated; + $transition_state = $live; $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } + + // build Workflow access control + + $access = array(); + + $draft = install_workflow_get_sid('Draft', 'kwaltz_workflow'); + $in_moderation = install_workflow_get_sid('In Moderation', 'kwaltz_workflow'); + $is_moderated = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); + $live = install_workflow_get_sid('Live', 'kwaltz_workflow'); + + $moderation_workflow_states = array_keys(workflow_get_states($moderation_workflow)); + + $rids = array_keys(user_roles(FALSE)); + + // default permissions are unchecked + $zeros = array(); + foreach ($rids as $rid) { + $zeroes[$rid] = 0; + } + + foreach ($moderation_workflow_states as $moderation_workflow_state) { + $access[$moderation_workflow_state] = array( + 'view' => $zeroes, + 'update' => $zeroes, + 'delete' => $zeroes, + ); + } + + // override default access control permissions + $access[$draft]['view'][$publisher_rid] = $publisher_rid; + $access[$in_moderation]['update'][$moderator_rid] = $moderator_rid; + $access[$is_moderated]['update'][$publisher_rid] = $publisher_rid; + + // save the permissions + workflow_access_form_submit(array(), array('values' => array('workflow_access' => $access))); + // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
f82dae0b8cbd986717a0b9e43f4d95df091050b8
Remove hard-coded role IDs
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 628b8a3..ed2e65d 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,199 +1,204 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module - install_add_permissions(3, $author_permissions); - install_add_permissions(4, $moderator_permissions); - install_add_permissions(5, $publisher_permissions); + + $author_rid = install_get_rid('Writer'); + $moderator_rid = install_get_rid('Moderator'); + $publisher_rid = install_get_rid('Publisher'); + + install_add_permissions($author_rid, $author_permissions); + install_add_permissions($moderator_rid, $moderator_permissions); + install_add_permissions($publisher_rid, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); $original_state = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); $transition_state = install_workflow_get_sid('Live', 'kwaltz_workflow'); $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } - } + } // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
f07b7726b44d09378c12a3995544cda1bb671da2
Use my forked version of the Install Profile API instead of private functions in the profile. Make file updated.
diff --git a/make/kwaltz.make b/make/kwaltz.make index bb2d4e9..9c87fc7 100644 --- a/make/kwaltz.make +++ b/make/kwaltz.make @@ -1,56 +1,54 @@ core = 6.x projects[drupal][type] = core projects[drupal][download][type] = cvs projects[drupal][download][revision] = DRUPAL-6-16 projects[drupal][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[drupal][download][module] = drupal projects[smart_menus][type] = "module" projects[smart_menus][download][type] = "cvs" projects[smart_menus][download][module] = "contributions/modules/smart_menus" projects[smart_menus][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[smart_menus][download][revision] = "DRUPAL-6--1-5" projects[module_grants][type] = "module" projects[module_grants][download][type] = "cvs" projects[module_grants][download][module] = "contributions/modules/module_grants" projects[module_grants][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[module_grants][download][revision] = "DRUPAL-6--3-5" projects[revisioning][type] = "module" projects[revisioning][download][type] = "cvs" projects[revisioning][download][module] = "contributions/modules/revisioning" projects[revisioning][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[revisioning][download][revision] = "DRUPAL-6--3-10" projects[token][type] = module projects[token][download][type] = "cvs" projects[token][download][module] = "contributions/modules/token" projects[token][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[token][download][revision] = "DRUPAL-6--1-13" projects[workflow][type] = module projects[workflow][download][type] = "cvs" projects[workflow][download][module] = "contributions/modules/workflow" projects[workflow][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[workflow][download][revision] = "DRUPAL-6--1-4" projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_1.patch" projects[diff][type] = "module" projects[diff][download][type] = "cvs" projects[diff][download][module] = "contributions/modules/diff" projects[diff][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[diff][download][revision] = "DRUPAL-6--2-0" projects[features][type] = "module" projects[features][download][type] = "cvs" projects[features][download][module] = "contributions/modules/features" projects[features][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" projects[features][download][revision] = "DRUPAL-6--1-0-BETA8" projects[install_profile_api][type] = "module" -projects[install_profile_api][download][type] = "cvs" -projects[install_profile_api][download][module] = "contributions/modules/install_profile_api" -projects[install_profile_api][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" -projects[install_profile_api][download][revision] = "DRUPAL-6--2" \ No newline at end of file +projects[install_profile_api][download][type] = "git" +projects[install_profile_api][download][url] = "git://github.com/sillygwailo/install_profile_api.git" diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 300651f..628b8a3 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,247 +1,199 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } -/** - * Given a workflow machine name, return the numeric workflow ID - * - * Assumes the presence of the patch to add Features compatibility - * available at http://drupal.org/node/558378 - * - * @return - * numeric workflow ID - */ -function _install_workflow_get_wid($machine_name) { - $wid = db_result(db_query_range("SELECT wid FROM {workflows} WHERE machine_name ='%s'", $machine_name, 0, 1)); - return $wid; -} - -/** - * Get a workflow's transition ID based on the from state and the to states - * - * @param $from - * The numeric ID of the original state. - * @param $to - * The numeric ID of the transitioning-to state. - * @return - * A numeric transition ID. - */ -function _install_workflow_get_transition_id($from, $to) { - $tid = db_result(db_query("SELECT tid FROM {workflow_transitions} WHERE sid = %d AND target_sid = %d", $from, $to)); - return $tid; -} - -/** - * Get a workflow state ID from its name. - * - * @param $state_name - * A string containing the state's name - * @param $module - * A string containing the module that uses the state. Defaults to 'workflow' - * @return - * The numeric state ID. - */ -function _install_workflow_get_sid_by_name($state_name, $module = NULL) { - if (!isset($module)) { - $module = 'workflow'; - } - $sid = db_result(db_query("SELECT sid FROM {workflow_states} WHERE state = '%s' AND module = '%s'", $state_name, $module)); - return $sid; -} - - /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. - $moderation_workflow = _install_workflow_get_wid('moderation'); + $moderation_workflow = install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); - $original_state = _install_workflow_get_sid_by_name('Is Moderated', 'kwaltz_workflow'); - $transition_state = _install_workflow_get_sid_by_name('Live', 'kwaltz_workflow'); - $transition_id = _install_workflow_get_transition_id($original_state, $transition_state); + $original_state = install_workflow_get_sid('Is Moderated', 'kwaltz_workflow'); + $transition_state = install_workflow_get_sid('Live', 'kwaltz_workflow'); + $transition_id = install_workflow_get_transition_id($original_state, $transition_state); if ($transition_id) { // Thanks to http://drupal.org/node/822468 sample code to programmatically // assign actions. // // The Trigger module automatically adds a 'save post' action on a 'publish' action. module_load_include('inc', 'trigger', 'trigger.admin'); foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { if ($action['callback'] == 'node_publish_action') { $form_values['aid'] = $aid; $form_values['hook'] = 'workflow'; $form_values['operation'] = 'workflow-story-' . $transition_id;; trigger_assign_form_submit(array(), array('values' => $form_values)); } } } // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
b532323bc92855703a74b65e267459ab6013e6d7
Removing hard-coded transition ID. Also renamed a function for consistency, and check to see if a transition ID exists before creating a trigger.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 5a42516..300651f 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,207 +1,247 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Given a workflow machine name, return the numeric workflow ID * * Assumes the presence of the patch to add Features compatibility * available at http://drupal.org/node/558378 * * @return * numeric workflow ID */ -function _install_get_wid($machine_name) { +function _install_workflow_get_wid($machine_name) { $wid = db_result(db_query_range("SELECT wid FROM {workflows} WHERE machine_name ='%s'", $machine_name, 0, 1)); return $wid; } +/** + * Get a workflow's transition ID based on the from state and the to states + * + * @param $from + * The numeric ID of the original state. + * @param $to + * The numeric ID of the transitioning-to state. + * @return + * A numeric transition ID. + */ +function _install_workflow_get_transition_id($from, $to) { + $tid = db_result(db_query("SELECT tid FROM {workflow_transitions} WHERE sid = %d AND target_sid = %d", $from, $to)); + return $tid; +} + +/** + * Get a workflow state ID from its name. + * + * @param $state_name + * A string containing the state's name + * @param $module + * A string containing the module that uses the state. Defaults to 'workflow' + * @return + * The numeric state ID. + */ +function _install_workflow_get_sid_by_name($state_name, $module = NULL) { + if (!isset($module)) { + $module = 'workflow'; + } + $sid = db_result(db_query("SELECT sid FROM {workflow_states} WHERE state = '%s' AND module = '%s'", $state_name, $module)); + return $sid; +} + + /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. - $moderation_workflow = _install_get_wid('moderation'); + $moderation_workflow = _install_workflow_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); - // Thanks to http://drupal.org/node/822468 sample code to programmatically - // assign actions. - // - // Workflow transition ID #7 hard-coded for now. The Trigger module - // automatically adds a 'save post' action. - module_load_include('inc', 'trigger', 'trigger.admin'); - foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { - if ($action['callback'] == 'node_publish_action') { - $form_values['aid'] = $aid; - $form_values['hook'] = 'workflow'; - $form_values['operation'] = 'workflow-story-7'; - trigger_assign_form_submit(array(), array('values' => $form_values)); + $original_state = _install_workflow_get_sid_by_name('Is Moderated', 'kwaltz_workflow'); + $transition_state = _install_workflow_get_sid_by_name('Live', 'kwaltz_workflow'); + $transition_id = _install_workflow_get_transition_id($original_state, $transition_state); + + if ($transition_id) { + + // Thanks to http://drupal.org/node/822468 sample code to programmatically + // assign actions. + // + // The Trigger module automatically adds a 'save post' action on a 'publish' action. + module_load_include('inc', 'trigger', 'trigger.admin'); + foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { + if ($action['callback'] == 'node_publish_action') { + $form_values['aid'] = $aid; + $form_values['hook'] = 'workflow'; + $form_values['operation'] = 'workflow-story-' . $transition_id;; + trigger_assign_form_submit(array(), array('values' => $form_values)); + } } - } + } // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
733bb716ffc396ebad8ae303dcf15a84c13e28dd
Add a trigger to set node status to published when workflow state changes from In Moderation to Live. Uses sample code from http://drupal.org/node/822468 Closes #2
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 2482598..5a42516 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,192 +1,207 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Given a workflow machine name, return the numeric workflow ID * * Assumes the presence of the patch to add Features compatibility * available at http://drupal.org/node/558378 * * @return * numeric workflow ID */ function _install_get_wid($machine_name) { $wid = db_result(db_query_range("SELECT wid FROM {workflows} WHERE machine_name ='%s'", $machine_name, 0, 1)); return $wid; } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // We know the workflow we'll need has the machine name 'moderation', // since that's what we use in the kwaltz_workflow features module. $moderation_workflow = _install_get_wid('moderation'); $workflow_types = array(); $workflow_types['story'] = array( 'workflow' => $moderation_workflow, 'placement' => array( 'node' => TRUE, 'comment' => FALSE ), ); workflow_types_save($workflow_types); + // Thanks to http://drupal.org/node/822468 sample code to programmatically + // assign actions. + // + // Workflow transition ID #7 hard-coded for now. The Trigger module + // automatically adds a 'save post' action. + module_load_include('inc', 'trigger', 'trigger.admin'); + foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { + if ($action['callback'] == 'node_publish_action') { + $form_values['aid'] = $aid; + $form_values['hook'] = 'workflow'; + $form_values['operation'] = 'workflow-story-7'; + trigger_assign_form_submit(array(), array('values' => $form_values)); + } + } + // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
f3d0bfa70e5727a145cb9fd216e68101b42fb325
Assign 'moderation' workflow to the Story content type. Also added a function to retrief the workflow wid based on machine name, assuming the patch to Workflow at http://drupal.org/node/558378 has been made. Closes #1
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index baabf00..2482598 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,165 +1,192 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } +/** + * Given a workflow machine name, return the numeric workflow ID + * + * Assumes the presence of the patch to add Features compatibility + * available at http://drupal.org/node/558378 + * + * @return + * numeric workflow ID + */ +function _install_get_wid($machine_name) { + $wid = db_result(db_query_range("SELECT wid FROM {workflows} WHERE machine_name ='%s'", $machine_name, 0, 1)); + return $wid; +} + /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); + // We know the workflow we'll need has the machine name 'moderation', + // since that's what we use in the kwaltz_workflow features module. + $moderation_workflow = _install_get_wid('moderation'); + $workflow_types = array(); + $workflow_types['story'] = array( + 'workflow' => $moderation_workflow, + 'placement' => array( + 'node' => TRUE, + 'comment' => FALSE + ), + ); + workflow_types_save($workflow_types); + // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
2eba0683ec085e84757c8f6b8bbaadc9b153b27f
Disable Color and Comment modules. Remove the Page content type. Set more options for the Story content type (unpublished, promoted to front page, new revisions, new revision in draft pending moderation.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 95a0faf..baabf00 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,177 +1,165 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { - $default = array('color', 'comment', 'help', 'menu', 'taxonomy', 'dblog'); + $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( - array( - 'type' => 'page', - 'name' => st('Page'), - 'module' => 'node', - 'description' => st("A <em>page</em>, similar in form to a <em>story</em>, is a simple method for creating and displaying information that rarely changes, such as an \"About us\" section of a website. By default, a <em>page</em> entry does not allow visitor comments and is not featured on the site's initial home page."), - 'custom' => TRUE, - 'modified' => TRUE, - 'locked' => FALSE, - 'help' => '', - 'min_word_count' => '', - ), array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. - variable_set('node_options_page', array('status')); - variable_set('comment_page', COMMENT_NODE_DISABLED); + variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
ecf693c7a8e8ecf06354a6c7d417c3a6442a2b5a
Actually store workflow values in the features module.
diff --git a/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc b/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc index 1345955..31f8e3a 100644 --- a/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc +++ b/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc @@ -1,71 +1,119 @@ <?php /** * Helper to implementation of hook_workflow_defaults(). */ function _kwaltz_workflow_workflow_defaults() { $defaults = array(); $defaults[] = array( 'name' => 'Moderation', 'machine_name' => 'moderation', 'tab_roles' => array( - '0' => NULL, + '0' => 'Moderator', + '1' => 'Publisher', + '2' => 'Writer', + ), + 'options' => array( + 'comment_log_node' => 1, + 'comment_log_tab' => 1, ), - 'options' => NULL, 'states' => array( '1' => array( 'ref' => '1', 'module' => 'kwaltz_workflow', 'state' => '(creation)', 'weight' => '-50', 'sysid' => '1', 'status' => '1', ), '2' => array( 'ref' => '2', 'module' => 'kwaltz_workflow', 'state' => 'Draft', 'weight' => '-10', 'sysid' => '0', 'status' => '1', ), '3' => array( 'ref' => '3', 'module' => 'kwaltz_workflow', 'state' => 'In Moderation', 'weight' => '-2', 'sysid' => '0', 'status' => '1', ), '4' => array( 'ref' => '4', 'module' => 'kwaltz_workflow', 'state' => 'Is Moderated', 'weight' => '2', 'sysid' => '0', 'status' => '1', ), '5' => array( 'ref' => '5', 'module' => 'kwaltz_workflow', 'state' => 'Live', 'weight' => '10', 'sysid' => '0', 'status' => '1', ), ), 'roles' => array( 'author' => array( 'name' => 'author', 'transitions' => array( '0' => array( 'from' => '1', 'to' => '2', ), + '1' => array( + 'from' => '5', + 'to' => '2', + ), + ), + ), + 'Moderator' => array( + 'name' => 'Moderator', + 'transitions' => array( + '0' => array( + 'from' => '3', + 'to' => '2', + ), + '1' => array( + 'from' => '3', + 'to' => '4', + ), + ), + ), + 'Publisher' => array( + 'name' => 'Publisher', + 'transitions' => array( + '0' => array( + 'from' => '4', + 'to' => '2', + ), + '1' => array( + 'from' => '4', + 'to' => '3', + ), + '2' => array( + 'from' => '4', + 'to' => '5', + ), + ), + ), + 'Writer' => array( + 'name' => 'Writer', + 'transitions' => array( + '0' => array( + 'from' => '2', + 'to' => '3', + ), ), ), ), ); return $defaults; }
sillygwailo/Kwaltz
8790a6473f4632409d0df96724fcf6900d8ba8f4
Disable Color and Comment modules. Remove the Page content type. Set more options for the Story content type (unpublished, promoted to front page, new revisions, new revision in draft pending moderation.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index 95a0faf..baabf00 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,177 +1,165 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { - $default = array('color', 'comment', 'help', 'menu', 'taxonomy', 'dblog'); + $default = array('help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( - array( - 'type' => 'page', - 'name' => st('Page'), - 'module' => 'node', - 'description' => st("A <em>page</em>, similar in form to a <em>story</em>, is a simple method for creating and displaying information that rarely changes, such as an \"About us\" section of a website. By default, a <em>page</em> entry does not allow visitor comments and is not featured on the site's initial home page."), - 'custom' => TRUE, - 'modified' => TRUE, - 'locked' => FALSE, - 'help' => '', - 'min_word_count' => '', - ), array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. - variable_set('node_options_page', array('status')); - variable_set('comment_page', COMMENT_NODE_DISABLED); + variable_set('node_options_story', array('promote', 'revision', 'revision_moderation')); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } // Build the workflow so that it shows up initially in // admin/build/workflow without having to visit // admin/build/features features_rebuild(); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
142b736c8961a430c4462a5c2baf35cef173c259
Disable Color and Comment modules. Remove the Page content type. Set more options for the Story content type (unpublished, promoted to front page, new revisions, new revision in draft pending moderation.
diff --git a/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc b/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc index 1345955..31f8e3a 100644 --- a/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc +++ b/modules/kwaltz_workflow/kwaltz_workflow.features.workflow.inc @@ -1,71 +1,119 @@ <?php /** * Helper to implementation of hook_workflow_defaults(). */ function _kwaltz_workflow_workflow_defaults() { $defaults = array(); $defaults[] = array( 'name' => 'Moderation', 'machine_name' => 'moderation', 'tab_roles' => array( - '0' => NULL, + '0' => 'Moderator', + '1' => 'Publisher', + '2' => 'Writer', + ), + 'options' => array( + 'comment_log_node' => 1, + 'comment_log_tab' => 1, ), - 'options' => NULL, 'states' => array( '1' => array( 'ref' => '1', 'module' => 'kwaltz_workflow', 'state' => '(creation)', 'weight' => '-50', 'sysid' => '1', 'status' => '1', ), '2' => array( 'ref' => '2', 'module' => 'kwaltz_workflow', 'state' => 'Draft', 'weight' => '-10', 'sysid' => '0', 'status' => '1', ), '3' => array( 'ref' => '3', 'module' => 'kwaltz_workflow', 'state' => 'In Moderation', 'weight' => '-2', 'sysid' => '0', 'status' => '1', ), '4' => array( 'ref' => '4', 'module' => 'kwaltz_workflow', 'state' => 'Is Moderated', 'weight' => '2', 'sysid' => '0', 'status' => '1', ), '5' => array( 'ref' => '5', 'module' => 'kwaltz_workflow', 'state' => 'Live', 'weight' => '10', 'sysid' => '0', 'status' => '1', ), ), 'roles' => array( 'author' => array( 'name' => 'author', 'transitions' => array( '0' => array( 'from' => '1', 'to' => '2', ), + '1' => array( + 'from' => '5', + 'to' => '2', + ), + ), + ), + 'Moderator' => array( + 'name' => 'Moderator', + 'transitions' => array( + '0' => array( + 'from' => '3', + 'to' => '2', + ), + '1' => array( + 'from' => '3', + 'to' => '4', + ), + ), + ), + 'Publisher' => array( + 'name' => 'Publisher', + 'transitions' => array( + '0' => array( + 'from' => '4', + 'to' => '2', + ), + '1' => array( + 'from' => '4', + 'to' => '3', + ), + '2' => array( + 'from' => '4', + 'to' => '5', + ), + ), + ), + 'Writer' => array( + 'name' => 'Writer', + 'transitions' => array( + '0' => array( + 'from' => '2', + 'to' => '3', + ), ), ), ), ); return $defaults; }
sillygwailo/Kwaltz
977995e69166145037e427acb0e59b9403687f73
Adding more comments, site name should now be initially set to the hostname like the default profile.
diff --git a/profiles/kwaltz/kwaltz.profile b/profiles/kwaltz/kwaltz.profile index b904307..95a0faf 100644 --- a/profiles/kwaltz/kwaltz.profile +++ b/profiles/kwaltz/kwaltz.profile @@ -1,173 +1,177 @@ <?php // $Id$ /** * Return an array of the modules to be enabled when this profile is installed. * * @return * An array of modules to enable. */ function kwaltz_profile_modules() { $default = array('color', 'comment', 'help', 'menu', 'taxonomy', 'dblog'); $contrib = array( 'module_grants', 'module_grants_monitor', 'node_tools', 'user_tools', 'profile', 'trigger', 'smart_tabs', 'diff', 'features', 'revisioning', 'token', 'token_actions', 'workflow', 'workflow_access', 'install_profile_api', 'kwaltz_workflow', ); return array_merge($default, $contrib); } /** * Return a description of the profile for the initial installation screen. * * @return * An array with keys 'name' and 'description' describing this profile, * and optional 'language' to override the language selection for * language-specific profiles. */ function kwaltz_profile_details() { return array( 'name' => 'Kwaltz', 'description' => 'A simple multi-step workflow. Based on the instructions at http://jamestombs.co.uk/2010-07-05/displaying-nodes-as-blocks-using-block-api/1252 .' ); } /** * Return a list of tasks that this profile supports. * * @return * A keyed array of tasks the profile will perform during * the final stage. The keys of the array will be used internally, * while the values will be displayed to the user in the installer * task list. */ function kwaltz_profile_task_list() { } /** * Perform any final installation tasks for this profile. * * @param $task * The current $task of the install system. When hook_profile_tasks() * is first called, this is 'profile'. * @param $url * Complete URL to be used for a link or form action on a custom page, * if providing any, to allow the user to proceed with the installation. * * @return * An optional HTML string to display to the user. Only used if you * modify the $task, otherwise discarded. */ function kwaltz_profile_tasks(&$task, $url) { // Insert default user-defined node types into the database. For a complete // list of available node type attributes, refer to the node type API // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info. $types = array( array( 'type' => 'page', 'name' => st('Page'), 'module' => 'node', 'description' => st("A <em>page</em>, similar in form to a <em>story</em>, is a simple method for creating and displaying information that rarely changes, such as an \"About us\" section of a website. By default, a <em>page</em> entry does not allow visitor comments and is not featured on the site's initial home page."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), array( 'type' => 'story', 'name' => st('Story'), 'module' => 'node', 'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, 'help' => '', 'min_word_count' => '', ), ); foreach ($types as $type) { $type = (object) _node_type_set_defaults($type); node_type_save($type); } // Default page to not be promoted and have comments disabled. variable_set('node_options_page', array('status')); variable_set('comment_page', COMMENT_NODE_DISABLED); // Don't display date and author information for page nodes by default. $theme_settings = variable_get('theme_settings', array()); $theme_settings['toggle_node_info_page'] = FALSE; variable_set('theme_settings', $theme_settings); // http://jamestombs.co.uk/2010-06-30/create-a-multi-step-moderation-process-in-drupal-6/1189 // Role names are slightly different to keep them distinct from the // terminology used in the Workflow module. "Author role", for example, // is renamed "Writer". They must proceed in this order, since the // required Features module assigns workflows to the numeric role ID. install_include(kwaltz_profile_modules()); install_add_role('Writer'); install_add_role('Moderator'); install_add_role('Publisher'); $moderator_permissions = array( 'access All tab', 'access I Can Edit tab', 'access I Can View tab', 'edit any story content', 'revert revisions', 'view revisions', 'access Pending tab', 'edit revisions', 'view revision status messages', ); $author_permissions = array( 'create story content', 'edit own story content', 'view revision status messages', 'view revisions of own story content', ); $publisher_permissions = array( 'access Published tab', 'access Unpublished tab', 'publish revisions', 'unpublish current revision', ); // Publisher permissions are a superset of Moderator's permissions $publisher_permissions = array_merge($moderator_permissions, $publisher_permissions); + // Role IDs are hard-coded and matched up with the IDs in the features module install_add_permissions(3, $author_permissions); install_add_permissions(4, $moderator_permissions); install_add_permissions(5, $publisher_permissions); // Workflow requires a permissions rebuild. Otherwise Drupal // complains, and manual intervention is necessary. if (node_access_needs_rebuild()) { node_access_rebuild(); } + // Build the workflow so that it shows up initially in + // admin/build/workflow without having to visit + // admin/build/features features_rebuild(); // Update the menu router information. menu_rebuild(); } /** * Implementation of hook_form_alter(). * * Allows the profile to alter the site-configuration form. This is * called through custom invocation, so $form_state is not populated. */ function kwaltz_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'install_configure') { // Set default for site name field. - $form['site_information']['site_name']['#kwaltz_value'] = $_SERVER['SERVER_NAME']; + $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } }
sillygwailo/Kwaltz
8b95b77e66118f7ee44346b218a135bb5d5f0ad9
Adding the Drush Make file
diff --git a/make/kwaltz.make b/make/kwaltz.make new file mode 100644 index 0000000..bb2d4e9 --- /dev/null +++ b/make/kwaltz.make @@ -0,0 +1,56 @@ +core = 6.x + +projects[drupal][type] = core +projects[drupal][download][type] = cvs +projects[drupal][download][revision] = DRUPAL-6-16 +projects[drupal][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[drupal][download][module] = drupal + +projects[smart_menus][type] = "module" +projects[smart_menus][download][type] = "cvs" +projects[smart_menus][download][module] = "contributions/modules/smart_menus" +projects[smart_menus][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[smart_menus][download][revision] = "DRUPAL-6--1-5" + +projects[module_grants][type] = "module" +projects[module_grants][download][type] = "cvs" +projects[module_grants][download][module] = "contributions/modules/module_grants" +projects[module_grants][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[module_grants][download][revision] = "DRUPAL-6--3-5" + +projects[revisioning][type] = "module" +projects[revisioning][download][type] = "cvs" +projects[revisioning][download][module] = "contributions/modules/revisioning" +projects[revisioning][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[revisioning][download][revision] = "DRUPAL-6--3-10" + +projects[token][type] = module +projects[token][download][type] = "cvs" +projects[token][download][module] = "contributions/modules/token" +projects[token][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[token][download][revision] = "DRUPAL-6--1-13" + +projects[workflow][type] = module +projects[workflow][download][type] = "cvs" +projects[workflow][download][module] = "contributions/modules/workflow" +projects[workflow][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[workflow][download][revision] = "DRUPAL-6--1-4" +projects[workflow][patch][] = "http://drupal.org/files/issues/558378-features-support-workflow_1.patch" + +projects[diff][type] = "module" +projects[diff][download][type] = "cvs" +projects[diff][download][module] = "contributions/modules/diff" +projects[diff][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[diff][download][revision] = "DRUPAL-6--2-0" + +projects[features][type] = "module" +projects[features][download][type] = "cvs" +projects[features][download][module] = "contributions/modules/features" +projects[features][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[features][download][revision] = "DRUPAL-6--1-0-BETA8" + +projects[install_profile_api][type] = "module" +projects[install_profile_api][download][type] = "cvs" +projects[install_profile_api][download][module] = "contributions/modules/install_profile_api" +projects[install_profile_api][download][root] = ":pserver:anonymous:[email protected]:/cvs/drupal" +projects[install_profile_api][download][revision] = "DRUPAL-6--2" \ No newline at end of file
intuited/xmlearn
faec630695db594a615b47fdcb397adad718beec
fix to allow dumping of non-node path locations.
diff --git a/__init__.py b/__init__.py index 89dd598..3ba1dcc 100755 --- a/__init__.py +++ b/__init__.py @@ -1,455 +1,460 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" # Copyright (C) 2010 Ted Tibbetts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') - title = title if title else '[{0}]'.format(element.tag) - path = element.getroottree().getpath(element) + title = (title if title + else '[{0}]'.format(element.tag + if hasattr(element, 'tag') else '')) + path = (element.getroottree().getpath(element) + if hasattr(element, 'getroottree') + else element.__class__) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: - for child in element.getchildren(): + for child in (element.getchildren() + if hasattr(element, 'getchildren') else []): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return ns.Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] p_dump.set_defaults(action=dump, outstream=out) # TODO: clean this up. It should be possible to use `choices`, but # it seems to want to list the options after they've been `type`d. dumpermap = {'default': Dumper, 'docbook': DocbookDumper} p_dump.add_argument('-f', '--format', dest="Dumper", metavar='XML_FORMAT', type=lambda key: dumpermap[key], default='default', choices=dumpermap.values(), help='The XML format or schema.\n' 'Defaults to generic XML.\n' 'xmlearn currently supports just generic ' 'and Docbook. Specifying `-f docbook` ' 'will enable the `book` ruleset ' 'to be specified via `-r book`.') # TODO: see if it's possible to use the default ruleset # for the Dumper selected with `-f`. p_dump.add_argument('-r', '--ruleset', default=Dumper.default_ruleset, help='Which set of rules to apply.\n') p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') def list_rulesets(ns): return ns.Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
47f7071ce06dc69f1e7c85ed404eb56b6d7f9ca9
cleanup format presentation and revise README
diff --git a/README.markdown b/README.markdown index e604da0..e6d0472 100644 --- a/README.markdown +++ b/README.markdown @@ -1,111 +1,118 @@ `xmlearn` ========= Library and CLI for learning about XML formats. ----------------------------------------------- `xmlearn` is a python module and command line utility which can be used to glean information about the structure of an XML document. The CLI commands map more or less directly to python functions. There are some lower-level python functions which are not provided as CLI commands. A major goal when developing this module was to learn about XML and Python support for it. I suspect that many of its functions are already better implemented elsewhere. Any suggestions are likely welcome. ### Distribution The code is maintained as a [repository] at http://github.com. ### License This code is copyright 2010 Ted Tibbetts and is licensed under the GNU Public License. See the file COPYING for details. ### Dependencies Requires [lxml] for all functionality. Requires [python-graph], [python-graph-dot], and [pydot] for graphing. The CLI uses the [argparse] module. Note that argparse is included with Python 2.7. Only tested with Python 2.6. ---------- ### CLI There are three CLI commands. The global `-i` option is used to pass an input file; this defaults to `stdin`. All three operate within the scope of an XPath provided by the global `-p` option; this path defaults to the root. usage: xmlearn [-h] [-i INFILE] [-p PATH] {graph,dump,tags} ... optional arguments: -h, --help show this help message and exit -i INFILE, --infile INFILE The XML file to learn about. Defaults to stdin. -p PATH, --path PATH An XPath to be applied to various actions. Defaults to the root node. #### dump The `dump` functionality pretty-prints the structure of the document under a given XPath. - usage: xmlearn dump [-h] [-l [RULESET]] [-r {full}] [-d MAXDEPTH] [-w WIDTH] [-v] + usage: xmlearn dump [-h] [-f XML_FORMAT] [-r RULESET] + [-d MAXDEPTH] [-w WIDTH] + [-l [RULESET]] [-v] Dump xml data according to a set of rules. optional arguments: -h, --help show this help message and exit - -l [RULESET], --list-rulesets [RULESET] - Get a list of rulesets or information about a particular ruleset - -r {full}, --ruleset {full} - Which set of rules to apply. Defaults to "full". + -f XML_FORMAT, --format XML_FORMAT + The XML format or schema. Defaults to generic XML. + xmlearn currently supports just generic and Docbook. + Specifying `-f docbook` will enable the `book` ruleset + to be specified via `-r book`. + -r RULESET, --ruleset RULESET + Which set of rules to apply. -d MAXDEPTH, --maxdepth MAXDEPTH How many levels to dump. -w WIDTH, --width WIDTH The output width of the dump. + -l [RULESET], --list-rulesets [RULESET] + Get a list of rulesets or information about a particular ruleset -v, --verbose Enable verbose ruleset list. Only useful with `-l`. #### tags `tags` provides info about the tags used in the document. Currently it can present either a list of tags or the list of tags which are children of a given tag. usage: xmlearn tags [-h] [-e] [-C] [-c [PARENT]] Show information about tags. optional arguments: -h, --help show this help message and exit -e, --show-element Enables display of the element path. Without this option, data from multiple matching elements will be listed in unbroken series. This is mostly useful when the path selects multiple elements. -C, --no-combine Do not combine results from various path elements. This option is only meaningful when the --path leads to multiple elements. -c [PARENT], --child [PARENT] List all tags which appear as children of PARENT. #### graph Builds an image file containing a graph of the tag relationships within the XML document. Any formats supported by `pydot` can be used for the resulting image file. usage: xmlearn graph [-h] [--format FORMAT] [-F FORCE_EXTENSION] outfile Build a graph from the XML tags relationships. positional arguments: outfile The filename for the graph image. If no --format is given, it will be based on this name. optional arguments: -h, --help show this help message and exit --format FORMAT The format for the graph image. It will be appended to the filename unless they already concur or -F is passed. -F FORCE_EXTENSION, --force-extension FORCE_EXTENSION Allow the filename extension to differ from the file format. Without this option, the format extension will be appended to the filename. [repository]: http://github.com/intuited/xmlearn [lxml]: http://pypi.python.org/pypi/lxml [python-graph]: http://pypi.python.org/pypi/python-graph/1.7.0 [python-graph-dot]: http://pypi.python.org/pypi/python-graph-dot/1.7.0 [pydot]: http://pypi.python.org/pypi/pydot/1.0.2 [argparse]: http://pypi.python.org/pypi/argparse/1.1 diff --git a/__init__.py b/__init__.py index 75f468f..89dd598 100755 --- a/__init__.py +++ b/__init__.py @@ -1,448 +1,455 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" # Copyright (C) 2010 Ted Tibbetts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return ns.Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] p_dump.set_defaults(action=dump, outstream=out) - # TODO: see if it's possible to use the default ruleset - # for the Dumper selected with `-f`. - p_dump.add_argument('-r', '--ruleset', - default=Dumper.default_ruleset, - help='Which set of rules to apply.\n') - + # TODO: clean this up. It should be possible to use `choices`, but + # it seems to want to list the options after they've been `type`d. dumpermap = {'default': Dumper, 'docbook': DocbookDumper} p_dump.add_argument('-f', '--format', dest="Dumper", + metavar='XML_FORMAT', type=lambda key: dumpermap[key], default='default', choices=dumpermap.values(), - help='The dump format.\n' - 'Defaults to full recursion.') + help='The XML format or schema.\n' + 'Defaults to generic XML.\n' + 'xmlearn currently supports just generic ' + 'and Docbook. Specifying `-f docbook` ' + 'will enable the `book` ruleset ' + 'to be specified via `-r book`.') + + # TODO: see if it's possible to use the default ruleset + # for the Dumper selected with `-f`. + p_dump.add_argument('-r', '--ruleset', + default=Dumper.default_ruleset, + help='Which set of rules to apply.\n') p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') def list_rulesets(ns): return ns.Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
e254364fc4782ef22e58b34dcfcedc8333520bfd
add option to select format, eg Docbook.
diff --git a/__init__.py b/__init__.py index bcd5c6a..75f468f 100755 --- a/__init__.py +++ b/__init__.py @@ -1,441 +1,448 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" # Copyright (C) 2010 Ted Tibbetts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return ns.Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] p_dump.set_defaults(action=dump, outstream=out) + # TODO: see if it's possible to use the default ruleset + # for the Dumper selected with `-f`. p_dump.add_argument('-r', '--ruleset', - choices=Dumper.rulesets.keys(), default=Dumper.default_ruleset, - help='Which set of rules to apply.\n' - 'Defaults to "{0}".' - .format(Dumper.default_ruleset)) + help='Which set of rules to apply.\n') + + dumpermap = {'default': Dumper, 'docbook': DocbookDumper} + p_dump.add_argument('-f', '--format', dest="Dumper", + type=lambda key: dumpermap[key], + default='default', + choices=dumpermap.values(), + help='The dump format.\n' + 'Defaults to full recursion.') p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') def list_rulesets(ns): return ns.Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
81a9ebe6161d8c3e3e93000560b74bfb0ed99826
tuck dump code into build_dump_parser
diff --git a/__init__.py b/__init__.py index 0800e03..bcd5c6a 100755 --- a/__init__.py +++ b/__init__.py @@ -1,443 +1,441 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" # Copyright (C) 2010 Ted Tibbetts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action - def instantiate_dumper(ns): - kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] - kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() - if key in kw_from_ns and value is not None) - return Dumper(**kwargs) - - def dump(ns): - """Initializes a Dumper with values from the namespace `ns`. - - False values are filtered out. - Dumps `ns.path` from the XML file `ns.infile`. - """ - dumper = instantiate_dumper(ns) - root = etree.parse(ns.infile).getroot() - return [dumper.dump(e) for e in ns.path(root)] - - def list_rulesets(ns): - return Dumper.print_rulesets(ruleset=ns.ruleset, - verbose=ns.verbose) - - parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') + def instantiate_dumper(ns): + kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] + kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() + if key in kw_from_ns and value is not None) + return ns.Dumper(**kwargs) + + def dump(ns): + """Initializes a Dumper with values from the namespace `ns`. + + False values are filtered out. + Dumps `ns.path` from the XML file `ns.infile`. + """ + dumper = instantiate_dumper(ns) + root = etree.parse(ns.infile).getroot() + return [dumper.dump(e) for e in ns.path(root)] + p_dump.set_defaults(action=dump, outstream=out) p_dump.add_argument('-r', '--ruleset', choices=Dumper.rulesets.keys(), default=Dumper.default_ruleset, help='Which set of rules to apply.\n' 'Defaults to "{0}".' .format(Dumper.default_ruleset)) p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') + def list_rulesets(ns): + return ns.Dumper.print_rulesets(ruleset=ns.ruleset, + verbose=ns.verbose) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
3e66c954bc1acd996eb7c962ed4eb4deee8dfa56
rearrange dump options.
diff --git a/__init__.py b/__init__.py index a849efe..0800e03 100755 --- a/__init__.py +++ b/__init__.py @@ -1,443 +1,443 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" # Copyright (C) 2010 Ted Tibbetts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] def list_rulesets(ns): return Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') p_dump.set_defaults(action=dump, outstream=out) - class ListRulesetsAction(Action): - def __call__(self, parser, namespace, values, option_string=None): - setattr(namespace, 'action', list_rulesets) - setattr(namespace, 'ruleset', values) - p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', - nargs='?', action=ListRulesetsAction, - help='Get a list of rulesets ' - 'or information about a particular ruleset') - p_dump.add_argument('-r', '--ruleset', choices=Dumper.rulesets.keys(), default=Dumper.default_ruleset, help='Which set of rules to apply.\n' 'Defaults to "{0}".' .format(Dumper.default_ruleset)) p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') + + class ListRulesetsAction(Action): + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, 'action', list_rulesets) + setattr(namespace, 'ruleset', values) + p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', + nargs='?', action=ListRulesetsAction, + help='Get a list of rulesets ' + 'or information about a particular ruleset') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
80b120c7ce2c95473fbfb3486c30e0562a4aada6
add documentation and license information
diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/README b/README deleted file mode 100644 index a3cdbc0..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -Library and CLI for learning about XML formats. diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..e604da0 --- /dev/null +++ b/README.markdown @@ -0,0 +1,111 @@ +`xmlearn` +========= + +Library and CLI for learning about XML formats. +----------------------------------------------- + +`xmlearn` is a python module and command line utility which can be used to glean information about the structure of an XML document. + +The CLI commands map more or less directly to python functions. + +There are some lower-level python functions which are not provided as CLI commands. + +A major goal when developing this module was to learn about XML and Python support for it. I suspect that many of its functions are already better implemented elsewhere. Any suggestions are likely welcome. + +### Distribution +The code is maintained as a [repository] at http://github.com. + +### License +This code is copyright 2010 Ted Tibbetts and is licensed under the GNU Public License. See the file COPYING for details. + +### Dependencies +Requires [lxml] for all functionality. + +Requires [python-graph], [python-graph-dot], and [pydot] for graphing. + +The CLI uses the [argparse] module. Note that argparse is included with Python 2.7. + +Only tested with Python 2.6. + +---------- + +### CLI +There are three CLI commands. + +The global `-i` option is used to pass an input file; this defaults to `stdin`. + +All three operate within the scope of an XPath provided by the global `-p` option; this path defaults to the root. + + usage: xmlearn [-h] [-i INFILE] [-p PATH] {graph,dump,tags} ... + + optional arguments: + -h, --help show this help message and exit + -i INFILE, --infile INFILE + The XML file to learn about. Defaults to stdin. + -p PATH, --path PATH An XPath to be applied to various actions. Defaults to the root node. + +#### dump +The `dump` functionality pretty-prints the structure of the document under a given XPath. + + usage: xmlearn dump [-h] [-l [RULESET]] [-r {full}] [-d MAXDEPTH] [-w WIDTH] [-v] + + Dump xml data according to a set of rules. + + optional arguments: + -h, --help show this help message and exit + -l [RULESET], --list-rulesets [RULESET] + Get a list of rulesets or information about a particular ruleset + -r {full}, --ruleset {full} + Which set of rules to apply. Defaults to "full". + -d MAXDEPTH, --maxdepth MAXDEPTH + How many levels to dump. + -w WIDTH, --width WIDTH + The output width of the dump. + -v, --verbose Enable verbose ruleset list. Only useful with `-l`. + +#### tags +`tags` provides info about the tags used in the document. Currently it can present either a list of tags or the list of tags which are children of a given tag. + + usage: xmlearn tags [-h] [-e] [-C] [-c [PARENT]] + + Show information about tags. + + optional arguments: + -h, --help show this help message and exit + -e, --show-element Enables display of the element path. + Without this option, data from multiple matching elements + will be listed in unbroken series. + This is mostly useful when the path selects multiple elements. + -C, --no-combine Do not combine results from various path elements. + This option is only meaningful when the --path leads to multiple elements. + -c [PARENT], --child [PARENT] + List all tags which appear as children of PARENT. + +#### graph +Builds an image file containing a graph of the tag relationships within the XML document. + +Any formats supported by `pydot` can be used for the resulting image file. + + usage: xmlearn graph [-h] [--format FORMAT] [-F FORCE_EXTENSION] outfile + + Build a graph from the XML tags relationships. + + positional arguments: + outfile The filename for the graph image. If no --format is given, + it will be based on this name. + + optional arguments: + -h, --help show this help message and exit + --format FORMAT The format for the graph image. + It will be appended to the filename unless they already concur or -F is passed. + -F FORCE_EXTENSION, --force-extension FORCE_EXTENSION + Allow the filename extension to differ from the file format. + Without this option, the format extension will be appended to the filename. + +[repository]: http://github.com/intuited/xmlearn + +[lxml]: http://pypi.python.org/pypi/lxml +[python-graph]: http://pypi.python.org/pypi/python-graph/1.7.0 +[python-graph-dot]: http://pypi.python.org/pypi/python-graph-dot/1.7.0 +[pydot]: http://pypi.python.org/pypi/pydot/1.0.2 +[argparse]: http://pypi.python.org/pypi/argparse/1.1 diff --git a/__init__.py b/__init__.py index 918a858..a849efe 100755 --- a/__init__.py +++ b/__init__.py @@ -1,428 +1,443 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" +# Copyright (C) 2010 Ted Tibbetts +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) from itertools import product basetags = product(bases, tags) tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] def list_rulesets(ns): return Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') p_dump.set_defaults(action=dump, outstream=out) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-r', '--ruleset', choices=Dumper.rulesets.keys(), default=Dumper.default_ruleset, help='Which set of rules to apply.\n' 'Defaults to "{0}".' .format(Dumper.default_ruleset)) p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)
intuited/xmlearn
ec62b195ec65addb6124f5f925aded8b21814b25
fix bug that was causing incomplete results from iter_unique_child_tags
diff --git a/__init__.py b/__init__.py index 5085902..918a858 100755 --- a/__init__.py +++ b/__init__.py @@ -1,426 +1,428 @@ #!/usr/bin/env python """Library and CLI for learning about XML formats.""" from lxml import etree class Dumper(object): """Dump an lxml.etree tree starting at `element`. Attributes: maxdepth: the maximum recursion level. width: the width at which text will be wrapped. ruleset: either a string matching one of the keys of rulesets, or a Mapping containing such a ruleset. outstream: a stream to which the dump will be written. For now, this function is just useful for sussing out the shape of the XML. """ # TODO: write doctest examples # Each ruleset maps tags to kwargs for `format_element`. rulesets = {'full': {None: {'recurse': True}}} default_ruleset = 'full' from sys import stdout outstream = stdout from pprint import PrettyPrinter pformat = PrettyPrinter(indent=2).pformat # Some more defaults. maxdepth = None width = 80 # This should maybe be moved into the CLI. @classmethod def print_rulesets(cls, ruleset=None, outstream=None, format=pformat, verbose=False): """Output ruleset information. If a `ruleset` is given, that ruleset's rules are output. If no `ruleset` is given, a list of rulesets is output. The `verbose` option will cause full ruleset information to be given in the list of rulesets. `format` can be used to specify a different formatting function. """ outstream = outstream if outstream else cls.outstream if ruleset: outstream.write(format(cls.rulesets[ruleset])) else: if verbose: outstream.write(format(cls.rulesets)) else: outstream.writelines("\n".join(cls.rulesets.keys())) outstream.write("\n") def __init__(self, **kwargs): """Initialize object attributes documented in the class docstring.""" self.__dict__.update(kwargs) def relwrap(self, *args, **kwargs): """Wrap the text with an indent relative to the `depth` keyword arg. The text is indented 4 spaces for each level of depth. Wrapped lines are indented an extra 2 spaces. """ from textwrap import wrap depth = kwargs.pop('depth', 0) wrap_kwargs = dict({'initial_indent': ' ' * depth, 'subsequent_indent': ' ' * depth + ' '}) if hasattr(self, 'width'): wrap_kwargs.update(width=self.width) wrap_kwargs.update(kwargs) return "\n".join(wrap(*args, **wrap_kwargs)) def format_element(self, element, depth, linebreak=False, with_text=True): from textwrap import dedent title = getattr(element.find('title'), 'text', '') title = title if title else '[{0}]'.format(element.tag) path = element.getroottree().getpath(element) eltext = getattr(element, 'text', '') eltext = dedent(eltext if eltext else '') if linebreak: summary = "{0} ({1}):".format(title, path) return "\n".join([self.relwrap(summary, depth=depth), self.relwrap(eltext, depth=depth+1)]) else: fmt = "{0} ({1}): {2}" if with_text else "{0} ({1})" return self.relwrap(fmt.format(title, path, eltext), depth=depth) def dump(self, element, **kwargs): """Dump `element` according to `ruleset`. Keyword arguments: depth: the initial depth of the dump. Normally this will be 0. Additionally, the `outstream`, `maxdepth`, and `ruleset` object attributes can be overridden without modifying the object. If `ruleset` is not given, `self`'s default ruleset is used. I suspect that actually using XSLT would be a better way to do this. """ from copy import copy from collections import Mapping depth = kwargs.pop('depth', 0) # Pull variables from kwargs or self maxdepth, outstream = (kwargs.pop(v, getattr(self, v)) for v in ('maxdepth', 'outstream')) ruleset = kwargs.pop('ruleset', getattr(self, 'ruleset', self.default_ruleset)) if isinstance(ruleset, basestring): ruleset = self.rulesets[ruleset] assert isinstance(ruleset, Mapping) def _dump(element, depth=0): for rule in ruleset.iteritems(): if rule[0] == None: default = copy(rule[1]) elif rule[0] == element.tag: kwargs = copy(rule[1]) break else: assert vars().has_key('default') kwargs = default recurse = kwargs.pop('recurse', False) outstream.write(self.format_element(element, depth, **kwargs)) outstream.write("\n") if recurse: if maxdepth is None or maxdepth > depth: for child in element.getchildren(): _dump(child, depth + 1) _dump(element, depth=depth) def clone(dict, **additions): from copy import deepcopy copy = deepcopy(dict) copy.update(**additions) return copy class DocbookDumper(Dumper): """Dumper for docbook XML files.""" rulesets = clone(Dumper.rulesets, book={'section': {'with_text': False}, 'para': {'linebreak': True}, None: {'recurse': True}}) default_ruleset = 'book' def iter_unique_child_tags(bases, tags): """Iterates through unique child tags for combinations of `bases` and `tags`. `bases` and `tags` can be singular -- elements and strings -- or iterables of those respective types. """ # both elements and strings are iterable types, # so we need to check for those specific types. bases, tags = (iter((param,)) if isinstance(param, type) else iter(param) for (param, type) in ((bases, etree._Element), (tags, basestring))) - from itertools import chain - tag_nodes = (node for base in bases for tag in tags + from itertools import product + basetags = product(bases, tags) + + tag_nodes = (node for base, tag in basetags for node in base.iter(tag)) child_tags = (child.tag for node in tag_nodes for child in node.getchildren()) found_child_tags = set() for tag in child_tags: if tag not in found_child_tags: found_child_tags.add(tag) yield tag def iter_tag_list(bases): """List all unique tags at and under the `root` node. `bases` can be a single element or an iterable of them. """ bases = (iter((bases,)) if isinstance(bases, etree._Element) else iter(bases)) from itertools import chain tags = (node.tag for base in bases for node in base.iter() if hasattr(node, 'tag')) found_tags = set() for t in tags: if t not in found_tags: found_tags.add(t) yield t def build_tag_graph(bases): """Build a python-graph graph of the tag relationships. `bases` is an element or iterable of elements. """ from pygraph.classes.digraph import digraph g = digraph() tags = list(iter_tag_list(bases)) g.add_nodes(tags) # TODO: this is totally inefficient: # it makes more sense to do each base separately, # to avoid searching it for tags it doesn't have. # The better way is to build the set of all bases' edges. for tag in tags: for child in iter_unique_child_tags(bases, tag): g.add_edge((tag, child)) return g def write_graph(graph, filename, format='svg'): """Write a python-graph graph as an image. `format` can be any of those supported by pydot.Dot.write(). """ from pygraph.readwrite.dot import write dotdata = write(graph) from pydot import graph_from_dot_data dotgraph = graph_from_dot_data(dotdata) dotgraph.write(filename, format=format) def write_tag_graph(bases, filename, format='png'): """Build and write a graph of the tag relationships in `bases`. `bases` can be a single element or an iterable of them. """ graph = build_tag_graph(bases) write_graph(graph, filename, format=format) # TODO: refactor this as a class. def cli(args, in_, out, err, Dumper=Dumper): """Provide a command-line interface to the module functionality. Dumper: xmlearn.Dumper or subclass. Called in response to the `dump` subcommand. Note that this should be the *class*, not an instantiation of it. args: the arguments to be parsed. in_, out, err: open input/output/error files. """ from argparse import ArgumentParser, FileType, Action def instantiate_dumper(ns): kw_from_ns = ['width', 'maxdepth', 'ruleset', 'outstream'] kwargs = dict((key, value) for key, value in ns.__dict__.iteritems() if key in kw_from_ns and value is not None) return Dumper(**kwargs) def dump(ns): """Initializes a Dumper with values from the namespace `ns`. False values are filtered out. Dumps `ns.path` from the XML file `ns.infile`. """ dumper = instantiate_dumper(ns) root = etree.parse(ns.infile).getroot() return [dumper.dump(e) for e in ns.path(root)] def list_rulesets(ns): return Dumper.print_rulesets(ruleset=ns.ruleset, verbose=ns.verbose) parser = ArgumentParser() parser.add_argument('-i', '--infile', type=FileType, default=in_, help='The XML file to learn about.\n' 'Defaults to stdin.') parser.add_argument('-p', '--path', default='/*', type=etree.XPath, help='An XPath to be applied to various actions.\n' 'Defaults to the root node.') subparsers = parser.add_subparsers(title='subcommands') def build_dump_parser(subparsers): p_dump = subparsers.add_parser('dump', help='Dump xml data according to a set of rules.', description='Dump xml data according to a set of rules.') p_dump.set_defaults(action=dump, outstream=out) class ListRulesetsAction(Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, 'action', list_rulesets) setattr(namespace, 'ruleset', values) p_dump.add_argument('-l', '--list-rulesets', metavar='RULESET', nargs='?', action=ListRulesetsAction, help='Get a list of rulesets ' 'or information about a particular ruleset') p_dump.add_argument('-r', '--ruleset', choices=Dumper.rulesets.keys(), default=Dumper.default_ruleset, help='Which set of rules to apply.\n' 'Defaults to "{0}".' .format(Dumper.default_ruleset)) p_dump.add_argument('-d', '--maxdepth', type=int, help='How many levels to dump.') # TODO: set default width to console width # TODO: also apply the console width to the help display p_dump.add_argument('-w', '--width', type=int, help='The output width of the dump.') p_dump.add_argument('-v', '--verbose', action='store_true', help='Enable verbose ruleset list.\n' 'Only useful with `-l`.') build_dump_parser(subparsers) def build_tags_parser(subparsers): p_list = subparsers.add_parser('tags', help='Show information about tags.', description='Show information about tags.') def taglist(ns): root = etree.parse(ns.infile).getroot() itemfmt = ' {item}\n' if ns.show_element else '{item}\n' elements = ns.path(root) if ns.combine: elements = (elements,) eltfmt = lambda e: '[multiple elements]\n' else: eltfmt = lambda e: e.getroottree().getpath(e) + "\n" for element in elements: if ns.show_element: out.write(eltfmt(element)) for item in ns.tagfunc(element, *ns.tagfunc_args): out.write(itemfmt.format(item=item)) p_list.set_defaults(action=taglist, tagfunc=iter_tag_list, tagfunc_args=[]) p_list.add_argument('-e', '--show-element', action='store_true', help='Enables display of the element path.\n' 'Without this option, data from multiple matching elements ' 'will be listed in unbroken series.\n' 'This is mostly useful ' 'when the path selects multiple elements.') p_list.add_argument('-C', '--no-combine', action='store_false', dest='combine', help='Do not combine results ' 'from various path elements.\n' 'This option is only meaningful ' 'when the --path leads to multiple elements.') class ListChildrenAction(Action): """Change the tag function and set the extra argument.""" def __call__(self, parser, namespace, values, option_string=None): if values: setattr(namespace, 'tagfunc', iter_unique_child_tags) setattr(namespace, 'tagfunc_args', [values]) p_list.add_argument('-c', '--child', nargs='?', metavar='PARENT', action=ListChildrenAction, help='List all tags which appear as children of PARENT.') build_tags_parser(subparsers) def build_graph_parser(subparsers): try: from pydot import Dot formats = Dot().formats except ImportError: return p_graph = subparsers.add_parser('graph', help='Build a graph from the XML tags relationships.', description='Build a graph from the XML tags relationships.') def act(ns): extension = ns.outfile.split('.')[-1] if ns.format: if extension != ns.format: ns.outfile += '.' + ns.format else: if extension in formats: ns.format = extension root = etree.parse(ns.infile).getroot() write_tag_graph(ns.path(root), ns.outfile, ns.format) p_graph.set_defaults(action=act) p_graph.add_argument('--format', choices=formats, metavar='FORMAT', help='The format for the graph image.\n' 'It will be appended to the filename ' 'unless they already concur ' 'or -F is passed.\n' 'Choose from ' + str(formats)) p_graph.add_argument('-F', '--force-extension', help='Allow the filename extension to differ ' 'from the file format.\n' 'Without this option, the format extension ' 'will be appended to the filename.') p_graph.add_argument(dest='outfile', default=None, help='The filename for the graph image.\n' 'If no --format is given, ' 'it will be based on this name.') build_graph_parser(subparsers) namespace = parser.parse_args(args) return namespace.action(namespace) if __name__ == '__main__': from sys import argv, stdin, stdout, stderr cli(argv[1:], stdin, stdout, stderr)