<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP_DCT_CreateSetup",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@vDSP_DCT_CreateSetup"
  },
  "title" : "vDSP_DCT_CreateSetup"
}
-->

# vDSP_DCT_CreateSetup

Builds a data structure that contains precalculated data to perform a discrete cosine transform.

```
vDSP_DFT_SetupvDSP_DCT_CreateSetup(vDSP_DFT_Setup __Previous, vDSP_Length __Length, vDSP_DCT_Type __Type);
```

## Parameters

`__Previous`

An existing [`vDSP_DFT_Setup`](/documentation/Accelerate/vDSP_DFT_Setup) structure that shares memory with the returned setup structure. Pass `nil` to create an object with newly initialized and allocated memory.

`__Length`

The number of real elements to transform. The supported values are `Length` = *f* * 2***n*, where *f* is 1, 3, 5, or 15 and *n* is at least 4.

`__Type`

A constant that defines which discrete cosine transform (DCT) variant to perform.

## Return Value

When successful, this function returns a [`vDSP_DFT_Setup`](/documentation/Accelerate/vDSP_DFT_Setup) structure. When unsuccessful, this function returns `nil`, either because of insufficient memory or because `Length` doesn’t satisfy the requirements given above.

## Discussion> Important:
> To prevent potential memory leaks, if the `Previous` parameter is not `nil`, the return value and the `Previous` value must be different variables.

## Discussion

Use this function to create a new setup structure. Don’t use the return value to reconfigure an existing setup structure passed to this function as the `Previous` parameter.

The following code creates two setup structures that share the same memory. Note that you must call [`vDSP_DFT_DestroySetup`](/documentation/Accelerate/vDSP_DFT_DestroySetup) for both setup structures. Destroying a setup with shared data is safe; the destroy function only releases memory that’s not needed by other undestroyed setups.

```swift
var signal = [ ... ]

guard
    // Create the first setup object.
    let setupForward = vDSP_DCT_CreateSetup(nil,
                                            vDSP_Length(signal.count),
                                            .II),
    // Create the second setup object that shares resources with `setupForward`.
    let setupInverse = vDSP_DCT_CreateSetup(setupForward,
                                            vDSP_Length(signal.count),
                                            .III) else {
    NSLog("Failed to create `vDSP_DCT_CreateSetup` setup structures.")
    return
}

// Perform DCT-II transform.
vDSP_DCT_Execute(setupForward,
                 signal,
                 &signal)

// `signal` contains frequency-domain representation of the original signal.

// Perform DCT-III transform.
vDSP_DCT_Execute(setupInverse,
                 signal,
                 &signal)

// `signal` contains time-domain representation of the original signal.

// Call `vDSP_DFT_DestroySetup` on both setup structures.
vDSP_DFT_DestroySetup(setupForward)
vDSP_DFT_DestroySetup(setupInverse)
```

You should only use the returned setup structure with [`vDSP_DCT_Execute`](/documentation/Accelerate/vDSP_DCT_Execute) using an input vector that contains `Length` elements.

## See Also

  <doc://com.apple.accelerate/documentation/Accelerate/understanding-data-packing-for-fourier-transforms>

  <doc://com.apple.accelerate/documentation/Accelerate/reducing-spectral-leakage-with-windowing>



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)