Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / media / base / audio_hash.h
blobec733832f7817d001a7caf60f310af975ccb4145
1 // Copyright 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.
5 #ifndef MEDIA_BASE_AUDIO_HASH_H_
6 #define MEDIA_BASE_AUDIO_HASH_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12 #include "media/base/media_export.h"
14 namespace media {
16 class AudioBus;
18 // Computes a running hash for a series of AudioBus objects. The hash is the
19 // sum of each sample bucketed based on the frame index, channel number, and
20 // current hash count. The hash was designed with two properties in mind:
22 // 1. Uniform error distribution across the input sample.
23 // 2. Resilience to error below a certain threshold.
25 // The first is achieved by using a simple summing approach and moving position
26 // weighting into the bucket choice. The second is handled during conversion to
27 // string by rounding out values to only two decimal places.
29 // Using only two decimal places allows for roughly -40 dBFS of error. For
30 // reference, SincResampler produces an RMS error of around -15 dBFS. See
31 // http://en.wikipedia.org/wiki/DBFS and http://crbug.com/168204 for more info.
32 class MEDIA_EXPORT AudioHash {
33 public:
34 AudioHash();
35 ~AudioHash();
37 // Update current hash with the contents of the provided AudioBus.
38 void Update(const AudioBus* audio_bus, int frames);
40 // Return a string representation of the current hash.
41 std::string ToString() const;
43 private:
44 // Storage for the audio hash. The number of buckets controls the importance
45 // of position in the hash. A higher number reduces the chance of false
46 // positives related to incorrect sample position. Value chosen by dice roll.
47 float audio_hash_[6];
49 // The total number of samples processed per channel. Uses a uint32 instead
50 // of size_t so overflows on 64-bit and 32-bit machines are equivalent.
51 uint32 sample_count_;
53 DISALLOW_COPY_AND_ASSIGN(AudioHash);
56 } // namespace media
58 #endif // MEDIA_BASE_AUDIO_HASH_H_