Twitch SDK (Internal)
converttounsignedoperator.h
Go to the documentation of this file.
1 /********************************************************************************************
2  * Twitch Broadcasting SDK
3  *
4  * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5  * may not be copied or used except in accordance with the terms of that agreement
6  * Copyright (c) 2012-2017 Twitch Interactive, Inc.
7  *
8  *********************************************************************************************/
9 
10 #pragma once
11 
13 
14 namespace ttv
15 {
30  template <typename InputSource, typename ContextType>
32  {
33  public:
34  ConvertToUnsignedOperator(ContextType& context)
35  : mInputSource(context)
36  {
37  }
38 
39  using InputSampleType = typename InputSource::SampleType;
40  static_assert(std::is_signed<InputSampleType>::value, "Input sample type must be signed.");
41  static_assert(std::is_integral<InputSampleType>::value, "Input sample type must be integral.");
42 
43  using SampleType = std::make_unsigned_t<InputSampleType>;
44  static constexpr size_t SampleRate = InputSource::SampleRate;
45 
46 
47  InputSource& GetInputSource()
48  {
49  return mInputSource;
50  }
51 
52 
54  {
55  return mInputSource.GetSampleRange();
56  }
57 
58 
59  SampleType operator[](size_t index) const
60  {
61  assert(index >= GetSampleRange().startIndex);
62  assert(index < GetSampleRange().startIndex + GetSampleRange().sampleCount);
63 
64  return (static_cast<SampleType>(mInputSource[index]) + static_cast<SampleType>(BisectRange<SampleType>()));
65  }
66 
67  private:
68  InputSource mInputSource;
69  };
70 }
SampleRange GetSampleRange() const
Definition: converttounsignedoperator.h:53
ConvertToUnsignedOperator(ContextType &context)
Definition: converttounsignedoperator.h:34
InputSource mInputSource
Definition: converttounsignedoperator.h:68
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
Definition: converttounsignedoperator.h:31
#define assert(expr)
Definition: assertion.h:47
Definition: dsputilities.h:60
SampleType operator[](size_t index) const
Definition: converttounsignedoperator.h:59
typename InputSource::SampleType InputSampleType
Definition: converttounsignedoperator.h:39
static constexpr size_t SampleRate
Definition: converttounsignedoperator.h:44
InputSource & GetInputSource()
Definition: converttounsignedoperator.h:47
std::make_unsigned_t< InputSampleType > SampleType
Definition: converttounsignedoperator.h:43