SampleEdit.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SampleEdit.h
  3. * ------------
  4. * Purpose: Basic sample editing code (resizing, adding silence, normalizing, ...).
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "FadeLaws.h"
  12. #include "../soundlib/Snd_defs.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. class CSoundFile;
  15. struct ModSample;
  16. struct ModChannel;
  17. namespace SampleEdit
  18. {
  19. enum ResetFlag
  20. {
  21. SmpResetCompo,
  22. SmpResetInit,
  23. SmpResetVibrato,
  24. };
  25. // Get a reference to all cue and loop points of the sample
  26. std::vector<std::reference_wrapper<SmpLength>> GetCuesAndLoops(ModSample &smp);
  27. // Insert silence to given location.
  28. // Note: Is currently implemented only for inserting silence to the beginning and to the end of the sample.
  29. // Return: Length of the new sample.
  30. SmpLength InsertSilence(ModSample &smp, const SmpLength silenceLength, const SmpLength startFrom, CSoundFile &sndFile);
  31. // Remove part of a sample [selStart, selEnd[.
  32. // Note: Removed memory is not freed.
  33. // Return: Length of the new sample.
  34. SmpLength RemoveRange(ModSample &smp, SmpLength selStart, SmpLength selEnd, CSoundFile &sndFile);
  35. // Change sample size.
  36. // Note: If resized sample is bigger, silence will be added to the sample's tail.
  37. // Return: Length of the new sample.
  38. SmpLength ResizeSample(ModSample &smp, const SmpLength newLength, CSoundFile &sndFile);
  39. // Resets samples.
  40. void ResetSamples(CSoundFile &sndFile, ResetFlag resetflag, SAMPLEINDEX minSample = SAMPLEINDEX_INVALID, SAMPLEINDEX maxSample = SAMPLEINDEX_INVALID);
  41. // Remove DC offset and normalize.
  42. // Return: If DC offset was removed, returns original offset value, zero otherwise.
  43. double RemoveDCOffset(ModSample &smp, SmpLength start, SmpLength end, CSoundFile &sndFile);
  44. // Amplify / fade sample data
  45. bool AmplifySample(ModSample &smp, SmpLength start, SmpLength end, double amplifyStart, double amplifyEnd, bool isFadeIn, Fade::Law fadeLaw, CSoundFile &sndFile);
  46. // Reverse sample data
  47. bool ReverseSample(ModSample &smp, SmpLength start, SmpLength end, CSoundFile &sndFile);
  48. // Virtually unsign sample data
  49. bool UnsignSample(ModSample &smp, SmpLength start, SmpLength end, CSoundFile &sndFile);
  50. // Invert sample data (flip by 180 degrees)
  51. bool InvertSample(ModSample &smp, SmpLength start, SmpLength end, CSoundFile &sndFile);
  52. // Crossfade sample data to create smooth loops
  53. bool XFadeSample(ModSample &smp, SmpLength fadeLength, int fadeLaw, bool afterloopFade, bool useSustainLoop, CSoundFile &sndFile);
  54. // Silence parts of the sample data
  55. bool SilenceSample(ModSample &smp, SmpLength start, SmpLength end, CSoundFile &sndFile);
  56. // Modify stereo separation of the sample data. separation is in range [-200, 200]
  57. bool StereoSepSample(ModSample &smp, SmpLength start, SmpLength end, double separation, CSoundFile &sndFile);
  58. // Convert 16-bit sample to 8-bit
  59. bool ConvertTo8Bit(ModSample &smp, CSoundFile &sndFile);
  60. // Convert 8-bit sample to 16-bit
  61. bool ConvertTo16Bit(ModSample &smp, CSoundFile &sndFile);
  62. // Convert ping-pong loops to regular loops
  63. bool ConvertPingPongLoop(ModSample &smp, CSoundFile &sndFile, bool sustainLoop);
  64. } // namespace SampleEdit
  65. OPENMPT_NAMESPACE_END