blob: 3e2c72eca8102b5f80fcf14a9a2409a8e5ba3e00 [file] [log] [blame]
Owen Linca365f82013-11-08 16:52:28 +08001# Copyright (c) 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5SOX_PATH = '/usr/local/bin/sox'
6
7def generate_sine_tone_cmd(
8 filename, channels=2, bits=16, rate=44100, duration=None, frequence=440,
9 gain=None):
10 """Gets a command to generate sine tones at specified ferquencies.
11
12 @param filename: the name of the file to store the sine wave in.
13 @param channels: the number of channels.
14 @param bits: the number of bits of each sample.
15 @param rate: the sampling rate.
16 @param duration: the length of the generated sine tone (in seconds).
17 @param frequence: the frequence of the sine wave.
18 @param gain: the gain (in db).
19 """
20 args = [SOX_PATH, '-n', '-t', 'raw']
21 args += ['-c', str(channels)]
22 args += ['-b', str(bits)]
23 args += ['-r', str(rate)]
24 args.append(filename)
25 args.append('synth')
26 if duration is not None:
27 args.append(str(duration))
28 args += ['sine', str(frequence)]
29 if gain is not None:
30 args += ['gain', str(gain)]
31 return args