summaryrefslogtreecommitdiff
path: root/cras/tools/create_volume_curve.py
blob: 13a0c59c91372de87b0e7188651292c0b3232c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
#
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import sys

def GenerateSimpleStep(name, max_volume, step_size):
  print '[%s]' % name
  print '  ; Generated by create_volume_curve.py'
  print '  ; simple_step curve, max %d, step %d' % (max_volume, step_size)
  print '  volume_curve = simple_step'
  print '  volume_step = %d' % step_size
  print '  max_volume = %d' % max_volume

def WriteExplicitCurveVal(step, value):
  print '  db_at_%d = %d' % (step, value)

def GenerateExplicit(name):
  print '[%s]' % name
  print '  ; Generated by create_volume_curve.py'
  print '  ; explicit curve'
  print '  volume_curve = explicit'
  for i in range(100):
    print 'Level at step %d:' % (100 - i)
    level = int(raw_input(">"))
    WriteExplicitCurveVal(100 - i, level)
  print 'Level at step 0:'
  level = int(raw_input(">"))
  WriteExplicitCurveVal(0, level)

def GenerateTwoSlope(name, max_volume, step_1, step_2, pivot_point):
  print '[%s]' % name
  print '  ; Generated by create_volume_curve.py'
  print ('  ; two_slope, max = %d, pivot = %d, steps %d, %d' %
         (max_volume, pivot_point, step_1, step_2))
  print '  volume_curve = explicit'
  for i in range(0, (100 - pivot_point)):
    WriteExplicitCurveVal(100 - i, max_volume - step_1 * i)
  pivot_dB_val = max_volume - step_1 * (100 - pivot_point)
  WriteExplicitCurveVal(pivot_point, max_volume - step_1 * (100 - pivot_point))
  for i in range(1, pivot_point):
    WriteExplicitCurveVal(pivot_point - i,  pivot_dB_val - step_2 * i)
  WriteExplicitCurveVal(0, pivot_dB_val - pivot_point * step_2)

def main():
  print 'What is the name of the jack or output to generate a curve for?'
  jack_name = raw_input(">");
  print 'Which type of curve? (simple_step, explicit, two_slope): '
  curve_type = raw_input(">");
  if curve_type == 'simple_step':
    print 'max volume (dBFS * 100):'
    max_volume = int(raw_input(">"))
    print 'step size (in dBFS * 100)'
    step_size = int(raw_input(">"))
    GenerateSimpleStep(jack_name, max_volume, step_size)
  elif curve_type == 'explicit':
    GenerateExplicit(jack_name)
  elif curve_type == 'two_slope':
    print 'max volume (dBFS * 100):'
    max_volume = int(raw_input(">"))
    print 'Volume step where slope changes:'
    pivot_point = int(raw_input(">"))
    print 'step size 100 to %d(in dBFS * 100)' % pivot_point
    step_1 = int(raw_input(">"))
    print 'step size %d to 0(in dBFS * 100)' % pivot_point
    step_2 = int(raw_input(">"))
    GenerateTwoSlope(jack_name, max_volume, step_1, step_2, pivot_point)

if __name__ == '__main__':
  main()